Блог пользователя myaw

Автор myaw, история, 8 лет назад, По-английски

Hi everyone.

I was trying to solve small input for this problem using recursive dp.

But it gives a strange runtime error when n >= 180000.

this my code

Any helps.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I think u have issues with stack size.

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    "u have" Is that mean that is my machine problem ? does it work for you ?

    • »
      »
      »
      8 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Yep, everything works fine on my PC, you should either allocate bigger stack or avoid recursion. (I believe it is not that hard in that task, simply use std::stack or array instead of recursion)

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You can also iterate backwards through the dp states before answering. If your dp recurrence goes "forward" ( dp(x) depends on dp values greater than x) fill the values from MAXN to 0. Doing that the program will never reach a recursion depth greater than 1. It is a cheap and fast way to fix this kind of issue.