@rahul, yes i agree with what you said, but I don't think that this is
causing WA here.. Its equivalent as if u take 2 1-darrays.. right?

On Wed, Sep 7, 2011 at 8:25 AM, rahul vatsa <[email protected]> wrote:

> if you are allocating memory for a n-d array, u shouldn't allocate memory
> for each row separately, wen u do that u get separate chunk of memory for
> each row, nd it breaks the basic rule of an array (i.e. array elements
> should be in contigious memory locations).
>
>
> On Tue, Sep 6, 2011 at 2:31 PM, Akshata Sharma 
> <[email protected]>wrote:
>
>> 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.
>>
>
>  --
> 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.
>

-- 
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.

Reply via email to