Advertisement
Farjana_akter

Untitled

Sep 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define MOD 10056
  5.  
  6. ll dp[10002],comb[1005][1005];
  7.  
  8. void combinationcalculation()
  9. {
  10. comb[1][0]=1;
  11. comb[1][1]=1;
  12. for(int i=2;i<=1001;i++)
  13. {
  14. comb[i][0]=1;
  15. for(int j=1;j<=i;j++)
  16. {
  17. comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
  18. comb[i][j]%=MOD;
  19. }
  20. }
  21. }
  22.  
  23.  
  24. ll process(ll n)
  25. {
  26. if(dp[n]!=-1)
  27. return dp[n];
  28. int ans=0;
  29. for(int i=1;i<=n;i++)
  30. {
  31. ans+=((comb[n][i])*(process(n-i)));
  32. ans%=MOD;
  33. }
  34. dp[n]=ans;
  35. return dp[n];
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41. // freopen("in.txt","r",stdin);
  42. // freopen("out.txt","w",stdout);
  43. combinationcalculation();
  44. ll n,i,j,k,cas,t;
  45. for(i=1;i<=1001;i++)
  46. dp[i]=-1;
  47. dp[0]=1;
  48. process(1001);
  49.  
  50. cin>>t;
  51. for(cas=1;cas<=t;cas++)
  52. {
  53. cin>>n;
  54. cout<<"Case "<<cas<<": "<<dp[n]<<endl;
  55. }
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement