title: Compute Ncr P Set 1 Introduction And Dynamic Programming Solution
signature: class Solution {
  
      public Integer computeNcrPSet1IntroductionAndDynamicProgrammingSolution(Integer n, Integer r, Integer p) {
source_py: def compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(n, r, p):
      C = [0 for i in range((r + 1))]
      C[0] = 1
      for i in range(1, (n + 1)):
          for j in range(min(i, r), 0, (- 1)):
              C[j] = ((C[j] + C[(j - 1)]) % p)
      return C[r]
source_cpp: int compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(int n, int r, int p) {
    int C [ r + 1 ];
    memset ( C, 0, sizeof ( C ) );
    C [ 0 ] = 1;
    for ( int i = 1;
    i <= n;
    i ++ ) {
      for ( int j = min ( i, r );
      j > 0;
      j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p;
    }
    return C [ r ];
  }
question_info.extension: java
question_info.entry_fn_name: computeNcrPSet1IntroductionAndDynamicProgrammingSolution
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 50, "inputs": {"n": 82, "r": 5, "p": 94}}, {"idx": 1, "outputs": 80, "inputs": {"n": 45, "r": 24, "p": 95}}, {"idx": 2, "outputs": 0, "inputs": {"n": 44, "r": 68, "p": 61}}, {"idx": 3, "outputs": 0, "inputs": {"n": 88, "r": 24, "p": 43}}, {"idx": 4, "outputs": 0, "inputs": {"n": 90, "r": 75, "p": 57}}, {"idx": 5, "outputs": 2, "inputs": {"n": 98, "r": 55, "p": 43}}, {"idx": 6, "outputs": 0, "inputs": {"n": 80, "r": 54, "p": 88}}, {"idx": 7, "outputs": 0, "inputs": {"n": 60, "r": 75, "p": 65}}, {"idx": 8, "outputs": 0, "inputs": {"n": 52, "r": 73, "p": 86}}, {"idx": 9, "outputs": 12, "inputs": {"n": 71, "r": 26, "p": 45}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer n, Integer r, Integer p, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(n, r, p,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(82, 5, 94, 50);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(45, 24, 95, 80);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(44, 68, 61, 0);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(88, 24, 43, 0);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(90, 75, 57, 0);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(98, 55, 43, 2);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(80, 54, 88, 0);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(60, 75, 65, 0);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(52, 73, 86, 0);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(71, 26, 45, 12);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer n, Integer r, Integer p, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(n, r, p),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__