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

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

Can anyone Suggest where my logic failed for this question, here is my solution which passed the example test cases, but when run the system test it gives the verdict as failed, Thank you.

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

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

I didn't solve this yet, but I think it's pick or leave dynamic programming problem, but you have to one more dimension to know if the first item picked! so the state is as follow:

F(N, picked) = Max(F(N-2, picked), F(N-1, picked)); 
F(0,0) = 0, F(0,1) = donations[0]; 
  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I know it's late but your not right maybe if we pick the first element then it will not be good enough.