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

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

Dear Friends,

I require some assistance concerning to my solution of this problem. I believe my logic is correct, but there are definitely some bugs in the code. My code is located here: http://ideone.com/t97fQ7

I will also explain my reasoning behind the solution: dp[a][b]: a set containing all number n such that there exists n numbers from the first a numbers that sum up to b. This set is stored as a long number. Therefore if the x bit in dp[a][b] is 1, then it's possible to find x such numbers that sum to b. As soon as that is cleared, the problem itself is a typical knapsack problem with the values being updated this way: dp[a][b]=(dp[a-1][b-V[a]] << 1) OR dp[a-1][b]

The shift <<1 happens because if we can form b-V[a] with q numbers, then we can form b with those q numbers and the V[a].

Does anyone have a clue as to why this code gets NZEC? Thank you in advance

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

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

You should handle special cases, like negative queries! (poor Jar Jar Binks)