I am getting WA in this problem, I am not getting what i am doing wrong
.....
http://www.spoj.pl/problems/AE2A/
My dp is:
dp[n][k] = (dp[n - 1][k - 1] + dp[n - 1][k - 2] + dp[n - 1][k - 3] + dp[n -
1][k - 4] + dp[n - 1][k - 5] + dp[n - 1][k - 6])
and my code:
#include<iostream>
using namespace std;
int solve(int n, int k)
{
int** dp;
dp = (int **)malloc(2*sizeof(int*));
dp[0]=(int*)malloc(1111111*sizeof(int));
dp[1]=(int*)malloc(1111111*sizeof(int));
for(int i=1;i<=6;i++)
dp[0][i]=1;
int throws=n;
n--;
int sum=0;
while(n--)
{
for(int i=1;i<=k;i++)
{
dp[1][i]=0;
sum=0;
for(int j=1;j<=6;j++)
{
if((i-j)<0) break;
sum+=dp[0][i-j];
}
dp[1][i]=sum;
}
for(int i=1;i<=k;i++)
dp[0][i]=dp[1][i];
}
dp[0][k]*=100;
for(int i=0;i<throws;i++)
dp[0][k]/=6;
return dp[0][k];
}
int main()
{
int cases;
cin>>cases;
while(cases--)
{
long n,k;
cin>>n>>k;
cout<<solve(n,k)<<endl;
}
return 0;
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.