Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

Hello! I am solving Pictures with Kittens (easy version).

My approach is pretty much like knapsack. Suppose we are at index i, we have 2 options either to not pick or to pick. If our last pick and current index different == k then we will have to pick it.

my dp state is dp[curr][taken][last] which is what is our answer if we are at index = curr, and have took taken elements and our previous taken = last.

But this approach is giving WA on test case 45. Can anyone please tell me what i am missing? The code is simple. Have a look at it.

Here is my solution: LINK

Thanks.

UPDATE: The solution got accepted when i declared res = minn instead of res = 0 which was earlier, can anyone tell me why this error.

AC

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