Tilling Problem Timelimit

Testcase 1 , 3,4,5 timelimit reached.

code with dynamic approach - https://ide.codingblocks.com/s/161358

recursive program - https://ide.codingblocks.com/s/161359

Let me know if there’s problem with the dynamic approach or perhaps with the recursive approach itself.

Your DP and recursive approach is coorect. You may be getting TLE because of Java being Slow. So I suggest you to write a iterative approach instead of memoization in the recursive approach. Both memoization and iterative DP are O(n) approaches but memoisation actually takes 2n time so using iterative will bw better as it takes n time.

Also I forgot to mention You didn’t mod (10^9 + 7) in your code. You must use (R1 + R2) % mod in you code.