UVA 10003 cuting Sticks cut sticks

Source: Internet
Author: User

Interval DP, cut DP[I][J] is not cost-independent (no validity)

DP[I][J] represents the cost of interval i,j, so as long as the enumeration of the cutting method is done, the interval is divided into smaller intervals. O (n^3)

Looked at the quadrilateral inequalities, proved too long.

#include <bits/stdc++.h>//variables don't take ignore left or something like that.using namespacestd;Const intMAXN =Wuyi;intCUT[MAXN];intDP[MAXN][MAXN];Const intINF =0x3fffffff;intMain () {//freopen ("In.txt", "R", stdin);    intL,n;  while(SCANF ("%d",&l) {scanf ("%d",&N); cut[0] =0; cut[n+1] =L;  for(inti =1; I <= N; i++) scanf ("%d", cut+i);  for(inti =0; I <= N; i++) dp[i][i+1] =0;  for(intD =1; D <= N; d++){             for(inti =0, MI = n-d; I <= mi; i++){                intj = i+d+1; DP[I][J]=INF;  for(intK = i+1; K < J; k++) {Dp[i][j]= Min (dp[i][j],dp[i][k]+Dp[k][j]); } Dp[i][j]+ = cut[j]-Cut[i]; }} printf ("The minimum cutting is%d.\n", dp[0][n+1]); }    return 0;}

UVA 10003 cuting Sticks cut sticks

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.