main idea
Interval DP, by definition, be an enumeration range DP. It represents the optimal solution with a range dp [i] [j], then the large interval from an inter combined, the final solution is obtained throughout a large interval.
Process enumeration algorithm is three, the first layer enumeration interval length, a second enumeration starting interval, the third layer enumeration division point intervals.
So that when the enumeration second layer, third layer ensures that the interval has passed enumeration.
State transition:
dp[i][j] = max(dp[i][j],dp[i][k]+dp[k+1][j]+w[i][j]);
template
Simple enumeration: the n- 3
memset(dp,0,sizeof(dp)) //初始dp数组
for(int len=1;len<=n;len++){ //第一层枚举区间长度
for(int i=0;i+len <= n;++i){ //枚举区间的起点
int j=i+len-1; //根据起点和长度得出终点
for(int k=i;k<=j;++k) //枚举分割点
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+w[i][j]);//状态转移方程
}
}
Quadrilateral optimized code: n- 2
for(int len=2;len<=n;len++){
for(int i = 1;i<=n;i++){
int j = i+len-1;
if(j>n) break;
for(int k = s[i][j-1];k<=s[i+1][j];k++){
if(dp[i][j]>dp[i][k]+dp[k+1][j]+w[i][j]){
dp[i][j]=dp[i][k]+dp[k+1][j]+w[i][j];
s[i][j]=k;
}
}
}
}