dp/Quadrilateral Inequalities
Naked title Ring Stone Merge ...
Remove the ring as a chain
1 //hdoj 35062#include <cmath>3#include <vector>4#include <cstdio>5#include <cstring>6#include <cstdlib>7#include <iostream>8#include <algorithm>9 #defineRep (i,n) for (int i=0;i<n;++i)Ten #defineF (i,j,n) for (int i=j;i<=n;++i) One #defineD (i,j,n) for (int i=j;i>=n;--i) A #definePB Push_back - #defineCC (A, B) memset (A,b,sizeof (a)) - using namespacestd; the intGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} - while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} + returnv*Sign ; - } + Const intn= .; A Const intinf=1000000000; at Const Doubleeps=1e-8; - /*******************template********************/ - intS[n][n],a[n]; - intDp[n][n]; - intMain () { - #ifndef Online_judge inFreopen ("Input.txt","R", stdin); - //freopen ("Output.txt", "w", stdout); to #endif + intN; - while(SCANF ("%d", &n)!=eof &&N) { theCC (A,0); CC (S,0); *F (I,1, N) a[i+n]=a[i]=getint (); $F (I,1,n<<1) a[i]+=a[i-1];Panax NotoginsengF (I,1N2-1){ -dp[i][i+1]=a[i+1]-a[i-1]; thes[i][i+1]=i; + } AF (Len,3, N) theF (I,1N2-len+1){ + intj=i+len-1; -dp[i][j]=INF; $F (k,s[i][j-1],s[i+1][j]) { $ inttmp=dp[i][k]+dp[k+1][j]+a[j]-a[i-1]; - if(tmp<Dp[i][j]) { -dp[i][j]=tmp; thes[i][j]=K; - }Wuyi } the } - intans=INF; WuF (I,1, N) ans=min (ans,dp[i][i+n-1]); -printf"%d\n", ans); About } $ return 0; -}View Code
"Hdoj" "3506" Monkey party