GDSUB Help needed

https://www.codechef.com/viewsolution/26626602

Only some testcases are showed correct. Can anyone help me with the issue? I have used dp with 2d array and prefix sum in each row.

Since k < n is also possible you should calculate your result like this –

int sum=1;
int z = min(n, k);
for(i=0;i<z;i++)sum=(sum+dp[i][n-1])%M;

2 Likes

@techfreak_19
Thanks a lot!

1 Like