We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
long dp[][] = new long[n+1][p+1];
long m = (long)10e9+7;
Arrays.fill(dp[1],1);
for(int i=1;i<=n-1;i++)
{
for(int j=1;j<=p;j++)
{
for(int k=1;k<=p/j;k++)
{
dp[i+1][k] += dp[i][j];
dp[i+1][k] %= m;
}
}
}
long sum=0;
for(int j=1;j<=p;j++)
{
sum += (dp[n][j]);
sum %= m;
}
return sum;
}
Can Anyone let me know why this code is giving me wrong answer. I am aware that it will give TLE and Memory problems.I just wanna know why it is logically wrong.
THank you.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
P-sequences
You are viewing a single comment's thread. Return to all comments →
static long pSequences(int n, int p) {
Can Anyone let me know why this code is giving me wrong answer. I am aware that it will give TLE and Memory problems.I just wanna know why it is logically wrong. THank you.