NO__IQ's blog

By NO__IQ, history, 13 days ago, In English

hello, my friends, I'm solving a DP problem on Cses and I got a time limit exceeded but I saw a solution for the problem using bottom-up technique but I got a time limit on top-down technique although we use the same approach

can someone explain why I get TLE ?

my code https://ideone.com/inIGo6

bottom-up solution https://ideone.com/Pp0EA5

Problem link https://cses.fi/problemset/task/1636

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
13 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by NO__IQ (previous revision, new revision, compare).

»
13 days ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Mostly, the time limit in the CSES set for DP is made just to accept iterative approach, as the recursive method is costly as compared to iterative, given the same constraints (See). Try making lesser operation in the recursive function or go for the iterative.

»
13 days ago, # |
  Vote: I like it +1 Vote: I do not like it

Please specify the problem you want to solve and the link to the problem.

»
13 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by NO__IQ (previous revision, new revision, compare).

»
13 days ago, # |
  Vote: I like it 0 Vote: I do not like it

It´s not your problem but it´s faster to use "const int mod" than "int mod"