sumit93's blog

By sumit93, 10 years ago, In English
My code


LLI rec(int room,int col)
{
if(room==0&&col==0)
return 1;
if(room==0||col==0)
return 0;
LLI &ans=dp[room][col];
if(ans!=-1)
return ans;
ans=0;
for(LLI i=1; i<=room; i++)
{
LLI temp=nCr(room,i)%mod;
temp=(temp*rec(room-i,col-1))%mod;
ans+=temp;
ans=ans%mod;
}
return ans%mod;
}

I am using this recursive dp to solve a problem.Suppose I have 200rooms and 35 colours. Here mod=1000000007. I have to colour every room using 35 colurs and every colour must be used.My function gives me wrong output. But I think it shoul give me correct otput. if room=200 and colour=35 , my function output: 872158314. But correct output shoul be : 35727139.Can anybody explain my logical bug in my function.

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
10 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Please explain the problem better, Its not clear to me. Thanks.