Advertisement
niamul64

///////////// pascle NCR

Jul 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. ///////////// pascle NCR
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define scInt(x,y) scanf("%d%d",&x,&y)
  5. int dp[1000][1000];
  6. int start;
  7. int NCR(int n,int r)
  8. {
  9.     if(dp[n][r])
  10.         return dp[n][r];
  11.     int i,j;
  12.     for(i=start; i<=n; i++)
  13.     {
  14.  
  15.  
  16.         for(j=0; j<=n; j++)
  17.         {
  18.  
  19.             if(i==j){
  20.  
  21.                 dp[i][j]=1;
  22.  
  23.             break;
  24.             }
  25.             if(j==0){
  26.  
  27.                 dp[i][j]=1;
  28.  
  29.             continue;
  30.             }
  31.             dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
  32.  
  33.  
  34.         }
  35.         if(dp[n][r])
  36.         {
  37.             start=i;
  38.             return dp[n][r];
  39.         }
  40.     }
  41. }
  42.  
  43.  
  44.  
  45. int main()
  46. {
  47.     start=0;
  48. int n,r;
  49.     while(scInt(n,r)!=EOF)
  50.     {
  51.  
  52.  
  53.         printf("NCR of %dc%d: %d\n",n,r,NCR(n,r));
  54.  
  55.  
  56.     }
  57.  
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement