title: Compute Ncr P Set 1 Introduction And Dynamic Programming Solution
signature: compute_ncr_p_set_1_introduction_and_dynamic_programming_solution <- function(n, r, p) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, r, p, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n, r, p), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          82L, 5L, 94L, 
          50L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          45L, 24L, 95L, 
          80L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          44L, 68L, 61L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          88L, 24L, 43L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          90L, 75L, 57L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          98L, 55L, 43L, 
          2L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          80L, 54L, 88L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          60L, 75L, 65L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          52L, 73L, 86L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          71L, 26L, 45L, 
          12L
      )))
  
  }
  
  main()
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 ];
  }