Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #define ll long long
- #define mp make_pair
- using namespace std;
- int N,H,M;
- const int maxn = 2500;
- const int maxh = 60;
- const int maxm = 70;
- ll dp[maxn+1][maxh+1][maxm+1];
- /* ll solve(ll ini,ll h,ll top){
- //each step there are two options --> top +- 1
- if (h>H || top<=0 || ini>N)
- return (dp[ini][h][top]=0);
- else if (h==H && top>0 && ini<=N)
- return (dp[ini][h][top]=1);
- else
- return (dp[ini][h][top] = solve(ini+1+top,h+1,top+1) + solve(ini-1+top,h+1,top-1));
- } */
- ll solve1(){
- for (int i=0;i<maxn;i++)
- for (int j=0;j<maxh;j++)
- for (int k=0;k<maxm;k++)
- dp[i][j][k] = 0LL;
- //dp[i][j][k]--> total of i blocks of height j and top block being k
- dp[M][1][M] = 1;//initially 1st level has m blocks
- ll lim = min(maxn,N);
- for (int i=1; i <= lim ; i++){
- for (int j=2; j <= H ; j++){
- for (int k = 1 ; k <= maxm ; k++){
- if ( (i >= k) && (k+1<=70) )
- dp[i][j][k] += dp[i-k][j-1][k+1];
- if ( (i >= k) && (k-1>=0) )
- dp[i][j][k] += dp[i-k][j-1][k-1];
- //cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<"\n";
- }
- }
- }
- ll ans = 0;
- for (int i=1 ; i <= lim ; i++)
- for (int j = 1; j <= 70 ; j++)
- ans = ans + dp[i][H][j];
- return ans;
- }
- int main(){
- //make a tower out of n cubes such that height is h and bottom has m cubes
- //thoughts- dp, think of a recurrence
- int t;
- scanf("%d",&t);
- while(t--){
- scanf("%d %d %d",&N,&H,&M);
- ll f =solve1();
- printf("%lld\n",f);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement