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

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

I am getting TLE and I can't handle it.I know the is solved by 0-1 Knapsack.I also try this. I think i have some mistake in my code but I do not found it. Please anyone help me..... Problem :UVA-562 — Dividing coins my code :Cpp_Code

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

»
9 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Consider the following test:

100

1 cent 99 times and 500 cents

Your solution will run up to O(2^n) in this case.

Add memo: for each state (i, sum) memoize the answer obtained so that you can get it in O(1) afterwards.