DHANANJAY AND CANDIES | CodeChef

can anyone help me how to solve this?

You can read up on Integer Partition of a number n into k parts :slight_smile:

Can u pls share a link for the same?? and why people’s solutions are not visible only for this problem??

1 Like

while(t–){
int n,k,i,j,p,l;
cin>>n>>k;
memset(dp,0,sizeof(dp));
dp[0][k][0]=1;
for(i=0;i<n;i++){
for(j=0;j<=k;j++){
for(l=0;l<=k;l++){
if(!dp[i][j][l])
continue;
for(p=l;p<=k;p++){
if(j-p>=0)
dp[i+1][j-p][p]+=dp[i][j][l];
}
}
}
}
ll ans=0;
for(i=0;i<=k;i++){
ans+=dp[n][0][i];
}
cout<<ans<<endl;
}

could you please give the recurrence relation and explain it a little bit as well