"Hdoj" "3506" Monkey party

Source: Internet
Author: User

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

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.