Do a number of interval DP topics, summarized as follows
1.Multiplication Puzzle
Original title address: http://poj.org/problem?id=1651
Test instructions
Given a sequence, you can sequentially remove elements from the sequence except for the left and right ends, each time taking an element and getting the number of points multiplied by the number of elements in the left and right sides of the element, to find the smallest possible number of points
Exercises
The last removed element in the enumeration interval, which realizes the segmentation of the interval, that is, the transition of the state.
Detailed Problem-solving report
2.Dire Wolf
Original title address: http://acm.split.hdu.edu.cn/showproblem.php?pid=5115
Test instructions
There are a group of wolves standing in a row, each wolf has the base of attack, while there is a secondary attack, each wolf's total attack is the base attack plus the neighboring wolves to give the aid of the sum of damage, the order to kill wolves to the total damage received and the smallest.
The problem: very similar to the previous one
#include <bits/stdc++.h>#defineCLR (x, Y) memset ((×), (y), sizeof (x))using namespaceStd;typedefLong LongLL;Const intmaxn= $;Const intinf=1e9;inta[maxn+5];intb[maxn+5];intdp[maxn+5][maxn+5];intN;intDP (intLintR) { if(dp[l][r]!=-1)returnDp[l][r]; if(l==r-1)returndp[l][r]=0; DP[L][R]=inf; for(intk=l+1; k<=r-1;++k) {inttmp=a[k]+b[l]+B[r]; DP[L][R]=min (DP[L][R],DP (l,k) +DP (k,r) +tmp); } returndp[l][r];}voidSolveintC) {a[0]=0; A[n+1]=0; b[0]=0; B[n+1]=0; CLR (DP,-1); intANS=DP (0, n+1); printf ("Case #%d:%d\n", C,ans);}intMainvoid) {#ifdef ex freopen (".. /in.txt","R", stdin); //freopen (".. /out.txt "," w ", stdout); #endif intT; scanf ("%d",&T); for(intCase=1; case<=t;++Case ) {scanf ("%d",&N); for(intI=1; i<=n;++i) scanf ("%d",&A[i]); for(intI=1; i<=n;++i) scanf ("%d",&C[i]); Solve (case); }}
View Code
3. The gift of the male gods
Original title address: http://acm.uestc.edu.cn/#/problem/show/1131
Test instructions: Slightly
The puzzle: slightly
#include <bits/stdc++.h>#defineCLR (x, Y) memset ((×), (y), sizeof (x))using namespaceStd;typedefLong LongLL;Const intmaxn= -;Const intinf=1e6;intN;intdp[maxn+5][maxn+5];inta[maxn+5];intsum[maxn+5];voidsolve () {CLR (DP,0); CLR (SUM,0); for(intI=1; i<=n;++i) sum[i]= (sum[i-1]+a[i])% -; for(inti=n;i>=1;--i) { for(intj=i;j<=n;++j) {Dp[i][j]=inf; if(I==J) dp[i][j]=0; for(intk=i;k<=j-1;++k) {intC1= (sum[k]-sum[i-1]+ -)% -; intC2= (sum[j]-sum[k]+ -)% -; DP[I][J]=min (dp[i][j],dp[i][k]+dp[k+1][j]+c1*C2); } //printf ("%d%d%d\n", i,j,dp[i][j]);}} printf ("%d\n", dp[1][n]);}intMainvoid) {#ifdef ex freopen (".. /in.txt","R", stdin); //freopen (".. /out.txt "," w ", stdout); #endif intT; scanf ("%d",&T); while(t--) {scanf ("%d",&N); for(intI=1; i<=n;++i) scanf ("%d",&A[i]); Solve (); }}
View Code
(For interval DP, the notation of loops is several times faster than memory, but it is also easier to write errors, including initialization, boundary conditions, etc.)
4.You is the one (difficult)
Original title address: http://acm.split.hdu.edu.cn/showproblem.php?pid=4283
Test instructions: Slightly
The puzzle: The interval segmentation is realized by enumerating the time of the left end of the enumeration interval.
Detailed Problem-solving report
5.Coloring Brackets
Original title address: Http://www.codeforces.com/contest/149/problem/D
Test instructions: Slightly
The puzzle: slightly
Detailed Problem-solving report
6. The love of the Prince
Original title address: http://acm.uestc.edu.cn/#/problem/show/1321
Test instructions: Slightly
The puzzle: Enumerates the paired parentheses of the left endpoint to achieve segmentation of the interval.
Detailed Problem-solving report
Summarize:
Interval DP mainly involves two kinds of problems, interval optimal solution and interval counting.
The interval optimal solution tends to enumerate the boundary points of the interval, dividing the interval, and the optimal solution of the sub-interval is the optimal solution of the original interval.
Interval counting often also divides the interval, but has not omitted the non-repetition request, above two questions all uses the enumeration left endpoint corresponding element the technique.
Segmentation of interval is an important thought of interval DP
Interval DP Summary