Interval Motion Regulation--triangle division of convex polygon

Source: Internet
Author: User

Given a convex polygon with n vertices (numbered 1 to n clockwise), the weights of each vertex are known. Ask how to divide this convex polygon into N-2 disjoint triangles, making the sum of the weights of the vertices of these triangles a minimum.

F[I][J] represents the smallest weight from the numbered I to J (clockwise) after the successive vertices are divided; then the problem solved becomes f[1][n]

The code is as follows:

#include <iostream>
#include <cstdio>
long long w[55],f[55][55];
int main () {
long long n,i,x,k,j;
scanf ("%i64d", &n);
for (i=1;i<=n;i++) scanf ("%i64d", &w[i]);
for (x=2;x<n;x++)    //consecutive vertex count for
  (i=1;i<=n-x;i++) {    //starting from the first vertex of the  
  j=i+x;
  f[i][j]=999999999999999999ll;//initial value should be large enough for
  (k=i+1;k<j;k++)
  f[i][j]=min (F[i][j],f[i][k]+f[k][j]+w[i] *W[K]*W[J]);  
  }
printf ("%i64d", F[1][n]);   
}

nkoj1463

Similar to Nkoj 2305 cut cake


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.