I solved the problem but as usual i kept the condition to check if my dp matrix contains the ans or not AT THE TOP. I was getting wrong ans. BUT when i kept the base condition at the top I got correct ans. PLZ explain me the reason.
My code is
https://ide.codingblocks.com/#/s/32962
Diwali problem DP
'cause if n is 0 and k is 0, you needa return 1 and not dp[n][k][last]
for whatever value of last and same for n=0 and k!=0 (return 0 irrespective of dp[n][k][last]
)
1 Like
thanks
1 Like