UVA - 10003 —— Cutting Sticks

Posted SuperChan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA - 10003 —— Cutting Sticks相关的知识,希望对你有一定的参考价值。

很基础的一道区间DP :)

#include <cstdio>
#include <iostream>
#define INF 0x3f3f3f3f
using namespace std;

int c[1005];
int dp[1005][1005];

int main ()
{
    int l, n;
    while(scanf("%d", &l)!=EOF && l) {
        scanf("%d", &n);
        for(int i=1; i<=n; i++) {
            scanf("%d", &c[i]);
        }
        c[0]=0;
        c[++n]=l;
        for(int step=2; step<=n; step++) {
            for(int i=0; i+step<=n; i++) {
                int j = i+step;
                dp[i][j] = INF;
                for(int k=i+1; k<j; k++) {
                    dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]+c[j]-c[i]);
                }
            }
        }
        printf("The minimum cutting is %d.\n", dp[0][n]);
    }
    return 0;
}

 

以上是关于UVA - 10003 —— Cutting Sticks的主要内容,如果未能解决你的问题,请参考以下文章

UVA-10003 Cutting Sticks (区间DP)

uva 10003 Cutting Sticks 区间dp

UVA10003 Cutting Sticks

UVA - 10003 Cutting Sticks(动态规划)

Cutting Sticks UVA - 10003

UVA 10003 Cutting Sticks 区间DP