码迷,mamicode.com
首页 > 其他好文 > 详细

UVA10003 Cutting Sticks

时间:2017-10-20 21:50:17      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:splay   swa   注意   click   size   can   pre   one   fine   

https://odzkskevi.qnssl.com/e17d84412b7ea3a42b6503109d6dfbc1?v=1508053531

 

【题解】

裸区间dp,注意一堆细节

 

技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <cmath>
 7 #define max(a, b) ((a) > (b) ? (a) : (b))
 8 #define min(a, b) ((a) < (b) ? (a) : (b))
 9 inline void swap(int &a, int &b)
10 {
11     int tmp = a;a = b;b = tmp;
12 }
13 inline void read(int &x)
14 {
15     x = 0;char ch = getchar(), c = ch;
16     while(ch < 0 || ch > 9)c = ch, ch = getchar();
17     while(ch <= 9 && ch >= 0)x = x * 10 + ch - 0, ch = getchar();
18     if(c == -)x = -x;
19 }
20 
21 const int INF = 0x3f3f3f3f;
22 const int MAXN = 50 + 10;
23 
24 int dp[MAXN][MAXN], po[MAXN], n, L;
25 
26 int main()
27 {
28     while(scanf("%d", &L) != EOF && L)
29     {
30         read(n);
31         for(register int i = 1;i <= n;++ i)
32             read(po[i]);
33         std::sort(po + 1, po + 1 + n);
34         for(register int i = 0;i <= n + 1;++ i) 
35             dp[i][i] = 0, dp[i][i + 1] = 0;
36         po[n + 1] = L;
37         for(register int k = 3;k <= n + 2;++ k)
38         {
39             for(register int i = 0;i <= n + 1;++ i)
40             {
41                 int j = i + k - 1;
42                 dp[i][j] = INF;
43                 if(j > n + 1)continue;
44                 for(register int m = i + 1;m < j;++ m)
45                     dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j] + po[j] - po[i]);
46             }
47         }
48         printf("The minimum cutting is %d.\n", dp[0][n + 1]);
49     }
50     return 0;
51 }                 
UVA10003

 

UVA10003 Cutting Sticks

标签:splay   swa   注意   click   size   can   pre   one   fine   

原文地址:http://www.cnblogs.com/huibixiaoxing/p/7701174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!