"Quadrilateral inequalities" Hdu3506-monkey party

Source: Internet
Author: User

"The main topic"

A group of monkeys (n<=1000) in the banana forest gathered around the meeting, and the President introduced them to each other, and each monkey needed time a[i]. Each time can only introduce the adjacent two monkeys x and y know, while x all know the monkeys and y all know the monkeys also know each other, the price of the two monkeys know Time (a[]) and the sum. The shortest time for the monkeys to know each other.

Ideas

Quadrilateral Inequalities Note ψ (. _.) >

Standard transfer equation format for quadrilateral inequalities:

W (I,J) to satisfy the quadrilateral inequalities when and only if both are satisfied:
When the ①j is constant, f (i) = W (i, J + 1)-W (i, j) is monotonically decreasing.
When the ②i is constant, f (j) = W (i + 1, j)-W (i, j) is monotonically decreasing.

When encountering the problem of the ring, copy the original array again, and the array length increases by one time.
DP[I][J] indicates that the monkeys from I to J are friends of the minimum time required, sum[i] is prefixed.
Dp[i][j]=min (Dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]), where W[i,j] =sum[j]-sum[i-1].

Obviously satisfies the quadrilateral inequality O (* ̄︶ ̄*) o

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intmaxn= ++ -;7 Const intinf=0x7fffffff;8 intN;9 inta[maxn*2],sum[maxn*2];Ten intdp[maxn*2][maxn*2],s[maxn*2][maxn*2]; One  A voidInit () - { -      for(intI=1; i<=n;i++) the     { -scanf"%d",&a[i]); -a[i+n]=A[i]; -     } +sum[0]=0; -      for(intI=1; i<=2*n;i++) sum[i]=sum[i-1]+A[i]; + } A  at voidSolve () - { -Memset (DP,0,sizeof(DP)); -memset (s),0,sizeof(s)); -      for(intI=1; i<=2*n;i++) s[i][i]=i; -      for(intI=2*n;i>=1; i--) in     { -          for(intj=i+1; j<=2*n;j++) to         { +dp[i][j]=INF; -              for(intk=s[i][j-1];k<=s[i+1][j];k++) the             { *                 if(dp[i][j]>dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]) $                 {Panax Notoginsengs[i][j]=K; -dp[i][j]=dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]; the                 } +             } A         } the     } +     intans=INF; -      for(intI=1; i<=n;i++) Ans=min (ans,dp[i][i+n-1]); $printf"%d\n", ans); $ } -  - intMain () the { -      while(SCANF ("%d", &n)! =EOF)Wuyi     { the init (); - solve (); Wu     } -     return 0; About}

"Quadrilateral inequalities" Hdu3506-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.