The main effect of the topic
A stick with a long l, with n "Tangent points" on it, and the position of each point is c[i]
We have to cut every point in a certain order, and then it turns into a n+1 segment.
Each time you cut, there is a cost, such as 10, "tangent" to 2, then the cut will become two paragraphs 2, 8, then the cost of 2+8=10
If you have more than one tangent, you will get different costs in different order.
How much is the minimum cost?
Ideas
Note To add a c[n] = l
F (I, j) represents the minimum cost of (I,J) intervals
F (i, j) = min{f (i,k) +f (k+1,j) +c[r]-c[l-1] | l<=k<k}
Code
/**========================================== * is a solution for ACM/ICPC problem * * @source: uva-10003 cuttin G sticks * @type: Interval DP * @author: Shuangde * @blog: blog.csdn.net/shuangde800 * @email: zengshuangde@gmail.com *========== =================================*/#include <iostream> #include <cstdio> #include <algorithm> #
include<vector> #include <queue> #include <cmath> #include <cstring> using namespace std;
typedef long long Int64;
const int INF = 0X3F3F3F3F;
const int MAXN = 55;
int l, N;
int C[MAXN];
int F[MAXN][MAXN]; int main () {while (~SCANF ("%d%d", &l, &n) && l) {for (int i = 0; i < n; ++i) scanf ("%d", &c[
I]);
C[n] = l; for (int d = 2; d <= n+1, ++d) {for (int l = 0; l + d-1 <= N; ++l) {int r = l + d-1; int& ans = f[l][r] = I
NF;
for (int k = l; k < R; ++k) {ans = min (ans, f[l][k]+f[k+1][r]+c[r]-c[l-1]);} printf ("The minimum cutting is%d.\ n ", F[0][n]);
return 0; }