Advertisement
shamiul93

1191 - Bar Codes

Oct 17th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. /**
  2. @author - Rumman BUET CSE'15
  3. Problem - 1191 - Bar Codes
  4. Topic- DP
  5. */
  6.  
  7. // LightOJ always needs this format for sure..so I made a copy of it...
  8. #include <bits/stdc++.h>
  9. #include<vector>
  10. #define ll                                      long long int
  11. #define fi                                      freopen("in.txt", "r", stdin)
  12. #define fo                                      freopen("out.txt", "w", stdout)
  13. #define m0(a) memset(a , 0 , sizeof(a))
  14. #define m1(a) memset(a , -1 , sizeof(a))
  15. #define inf LLONG_MAX
  16. #define min3(a,b,c) min(a,min(b,c))
  17. #define max3(a,b,c) max(a,max(b,c))
  18. #define ones(mask)  __builtin_popcount(mask) /// __builtin_popcount : it's a built in function of GCC. Finds out the numbers of 1 in binary representation.
  19. #define mx 150000
  20. #define mod 10056
  21.  
  22. using namespace std;
  23.  
  24. ll N, K, Max ;
  25. ll dp[60][60][60] ;
  26.  
  27.  
  28. ll solve(ll n, ll k , ll M)
  29. {
  30.     if(n == N && k == K) return  1 ;
  31.     if(n >= N || k >= K) return  0 ;
  32.  
  33.     if(dp[n][k][M] != -1) return dp[n][k][M] ;
  34.  
  35.     ll ans = 0 ;
  36.  
  37.     for(ll i = 1 ; i <= M ; i++)
  38.     {
  39.         ans += solve(n+i, k+1, M) ;
  40.     }
  41.  
  42.     dp[n][k][M] = ans ;
  43.     return dp[n][k][M] ;
  44.  
  45. }
  46.  
  47. int main()
  48. {
  49.     fi;
  50.     fo;
  51.     m1(dp);
  52.     ll T, t = 0 ;
  53.     scanf("%lld",&T) ;
  54.     while(T--)
  55.     {
  56.         t++ ;
  57.         scanf("%lld %lld %lld",&N,&K,&Max) ;
  58.         printf("Case %lld: ", t) ;
  59.  
  60.         ll ans ;
  61.         ans = solve(0,0,Max) ;
  62.         printf("%lld\n",ans) ;
  63.     }
  64.     return 0 ;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement