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

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

Автор avinash007, история, 3 года назад, По-английски

You are given N marbles in different colors. You have to remove marbles till there are no marbles left. Each time you can choose continuous marbles with the same color, remove them and get k*k points. Find the maximum points you can get.

1 ≤ N ≤ 100 0 ≤ Ai ≤ 100

INPUT 6 4 3 1 1 4 2 OUTPUT 10

Remove 1, then 3, then 4 and 2, we get 2*2+1*1+2*2+1*1 = 10

Please provide link to similar Problems.

Also I would like to know your dp states and Transitions

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

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

link the problem ?

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

Keep dp[i][j] as being the maximum score of the interval [i, j). For each of these intervals, look at the first element a[i]. You can either just do 1 + dp[i+1][j] or combine multiple occurrences of a[i] in this interval. Say these indices are t1, t2, t3, .... then for all prefixes of this sequence, you can update dp[i][j] with dp[t1+1][t2] + dp[t2+1][t3] + ... + dp[tk+1][j] + k*k. So you can just iterate for all possible k and get the max of them. You can check out the code here: code

EDIT: If you want a similar-style problem, I remember a classic one from the AtCoder DP contest N — Slimes