"Hdoj" "2829" Lawrence

Source: Internet
Author: User

dp/Quadrilateral Inequalities

After the POJ 1739 Post office that question, it is easy to write out the rules of the equation:

DP[I][J]=MIN{DP[I-1][K]+W[K+1][J]} (indicates the minimum cost of dividing the first J points into blocks i)

$w (l,r) =\sum_{i=l}^{r}\sum_{j=i+1}^{r}a[i]*a[j]$

Then there is $w (l,r+1) =w (l,r) +a[j]*\sum\limits_{i=l}^{r}a[i]$

So: W[i][j] clearly satisfies the monotonicity of the interval inclusions

Then we boldly guessed that the small (BU) Heart (Yong) proves that w[i][j] satisfies the quadrilateral inequality, so the question is the same as the post office.

All right, well, as a moral integrity, I try to prove it (the result is that it takes longer to prove than I write the code ...). )

First move the definition of W (i,j) Down: \[W (l,r) =\sum\limits_{i=l}^{r}\sum\limits_{j=i+1}^{r}a[i]*a[j] \]

The image is:

For $ i\leq i ' < J \leq J ' $

The middle is counted two times, the remainder:

(left) represents W (i,i '-1), [left] represents $\sum_{k=i}^{i ' -1}a[k] $

(medium) means w (i ', j), [medium] means $\sum_{k=i '}^j A[k] $

(right) means W (j+1,j '), [right] means $\sum_{k=j+1}^{j '} A[k] $

\[W (i,j) +w (i ', j ') = (left) +[left]*[]+ (right) +[right]*[] \ \ w (i,j ') +w (i ', j) = (left + right) +[left + right]*[] \]

    

where \[[left + right]*[in]=[left]*[]+[right]*[] \]

But \[(left + right) = (left) + (right) +[left]*[right] \]

So \[(left + right) > (left) + (right) \]

So \[w (i,j) +w (i ', J ') \leq W (i,j ') +w (i ', j) \]

1 //hdoj 28292#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=1010, inf=~0u>>2; A Const Doubleeps=1e-8; at #defineDebug - /*******************template********************/ - intdp[n][n],s[n][n],w[n][n],b[n],a[n],n,m; -  - intMain () { -      while(SCANF ("%d%d", &n,&m)!=eof &&N) { inm++; -F (I,1, N) a[i]=getint (); toF (I,1, N) { +b[i]=A[i]; -w[i][i]=0; theF (j,i+1, N) { *w[i][j]=w[i][j-1]+a[j]*B[i]; $b[i]+=A[j];Panax Notoginseng             } -         } theF (I,1, N) F (J,1, m) dp[j][i]=INF; +F (I,1, N) { Adp[1][i]=w[1][i]; thes[1][i]=0; +         } -F (I,2, M) { $s[i][n+1]=N; $ D (j,n,i) -F (k,s[i-1][j],s[i][j+1]) -                     if(dp[i-1][k]+w[k+1][j]<Dp[i][j]) { thes[i][j]=K; -dp[i][j]=dp[i-1][k]+w[k+1][j];Wuyi                     } the         } -printf"%d\n", Dp[m][n]); Wu     } -     return 0; About}
View Code

"Hdoj" "2829" Lawrence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.