atlasworld's blog

By atlasworld, history, 17 months ago, In English,

in problem zuma , why do we need a dp state like : as mentioned in tutorial

if(arr[i] == arr[i+1]) dp[i][j] = 1+dp[i+2][j]

i checked by removing this state and it gave WA .

why only these 2 dp states are not enough ! #@

dp[i][j] = 1+dp[i+1][j] and

dp[i][j] = dp[i+1][k-1] + dp[k+1][j]

CAN anyone clarify it more ? ! @

 
 
 
 
  • Vote: I like it
  • -20
  • Vote: I do not like it

»
17 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone??

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Let's take an example arr= [1, 1, 3], clearly dp[0][2] = 2, because [1, 1] and [3]

In the tutorial, it is mentioned 'k' is the index where (arr[i] == arr[k]), and dp[i][j] = dp[i+1][k-1] + dp[k+1][j]

So in the given example, arr[0]==arr[1], so i=0, and k=1. now using the above dp state dp[0][2] = dp[1][0] + dp[2][2], clearly dp[1][0] doesn't exist. That's why we need to handle this case with dp[i][j] = 1 + dp[i+2][j] if arr[i] = arr[i+1]