Advertisement
YEZAELP

PROG-1112: ลำดับสลับสับสน (inversion)

Jul 6th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int INF = 1e9;
  5.  
  6. int dp1[10001],dp2[10001];
  7.  
  8. int main(){
  9.  
  10.     int n,k;
  11.     scanf("%d%d",&n,&k);
  12.  
  13.     for(int i=0;i<=n;i++){
  14.         for(int j=0;j<=k;j++){
  15.             if(j == 0) dp2[j] = 1;
  16.             if(j == 0 or i == 0) continue;
  17.             for(int x=0;x<i;x++){
  18.                 if(j-x >=0 ) dp2[j] += dp1[j-x];
  19.             }
  20.             dp2[j] = dp2[j]%2012;
  21.         }
  22.         for(int j=0;j<=k;j++) {
  23.             dp1[j] = dp2[j];
  24.             dp2[j] = 0;
  25.         }
  26.     }
  27.  
  28.     printf("%d",dp1[k]);
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement