Interval training topics dp

Interval training topics dp

The meaning of problems

1.Equal Sum Partitions

? Well this thing, \ (the n-^ 2 \) to write to

\[\ \]

\[\ \]

2.You Are the One

Feel intelligence is suspended or beaten

\ (dp [i] [j ] \) , said current for an empty stack, \ (I \) to \ (J \) this period are popped minimum cost

Apparently looks a range(sly)dp(different)Look, how to transfer it? (Recommended to think of it)

For a \ (dp [i] [J] \) , because this \ (i \) must first be pushed onto the stack, so we can enumerate it popped time \ (k \) , then the total contribution is

\[dp[i+1][k]+(k-i)*a[i]+sum[k+1..j] \cdot (k-i+1)\]

That first-out stack \ (i + 1 ... k \ ) contribution and own contribution + i + \ (k + 1..j \) the contribution of this period was delayed, and they \ (k-i + 1 \) the contribution of bits generated

rep(i,1,n) rep(j,i+1,n) dp[i][j]=1e9;
rep(i,1,n) dp[i][i]=a[i];
drep(i,n,1) 
    rep(j,i,n) 
        rep(k,i,j) 
            dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k+1][j]+(k-i)*a[i]+(k-i+1)*(s[j]-s[k]));

Guess you like

Origin www.cnblogs.com/chasedeath/p/11331120.html