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

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

I was trying to solve This problem of Google APC 2015.

I did a o(n^4) Dp for finding the maximum number of elements that can be removed, keeping the starting and ending index of the array(say i,j) and two loops for transition in a state for finding all possible triplets in i to j range.

Let (a,b,c) is a triplet possible such that b-a=c-b=k where i<=a<=b<=c<=j

dp[i][j]=max(dp[i][j],3+dp[i][a-1]+dp[a+1][b-1]+dp[b+1][c-1]+dp[c+1][j])

Can someone give a better complexity solution...

Thanks

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

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

My DP solution:

canRemove(i, j) = (canRemove(i, k) and canRemove(k + 1, j)) or (satisfy(i, k, j) and canRemove(i + 1, k - 1) and canRemove(k + 1, j - 1))

length(i) = min(length(i - 1) + 1, length(j) if canRemove(j + 1, i))

The complexity is O(N^3).