Advertisement
Saleh127

UVA 12034

Jul 22nd, 2021
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. ll mod=10056;
  6. ll c[1005][1005],dp[1005];
  7.  
  8. void pre()
  9. {
  10. ll i,j,k,l;
  11.  
  12. ///nCr
  13. for(i=0; i<=1002; i++)
  14. {
  15. c[i][0]=1;
  16. for(j=1; j<=i; j++)
  17. {
  18. c[i][j]=(c[i][j]+c[i-1][j]+c[i-1][j-1])%mod;
  19. }
  20. }
  21.  
  22. dp[0]=1;
  23. dp[1]=1;
  24. dp[2]=3;
  25. dp[3]=13;
  26.  
  27. ///for all n ans(n) = nCr + ans(n-r);
  28. ///select r items for 1st then multilply the formation of n-r items
  29.  
  30. for(i=4; i<=1002; i++)
  31. {
  32. for(j=1; j<=i; j++)
  33. {
  34. dp[i]=(dp[i]+c[i][j]*dp[i-j])%mod;
  35. }
  36. }
  37.  
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43. ios_base::sync_with_stdio(0);
  44. cin.tie(0);
  45. cout.tie(0);
  46.  
  47.  
  48. pre();
  49.  
  50. test
  51. {
  52. ll n;
  53. cin>>n;
  54. cout<<"Case "<<cs<<": "<<dp[n]<<endl;
  55. }
  56.  
  57.  
  58. return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement