标签:
很基础的一道区间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; }
标签:
原文地址:http://www.cnblogs.com/AcIsFun/p/5335159.html