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

HDU4001To Miss Our Children Time【dp】

时间:2014-11-19 13:47:53      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   os   sp   

大意:有三种长方体木块,只有满足如下关系一个木块才可以放在另一个的上面

We describe each block‘s shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block‘s length and width must be more or equal to the block‘s length and width which lies under the block. When di = 1 the block‘s length and width must be more or equal to the block‘s length which lies under the block and width and the block‘s area must be more than the block‘s area which lies under the block. When di = 2 the block length and width must be more than the block‘s length and width which lies under the block. Here are some blocks.

问最大高度

分析  因为l和w都是一次递增的  所以只要把其排好序那么就可以dp了  后面的只会被前面的状态所决定

代码:

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 const long long maxn = 1005;
 8 
 9 struct Node {
10     long long l, w, h, d;
11 }node[maxn];
12 long long dp[maxn];
13 bool cmp(Node n1, Node n2) {
14     if(n1.l != n2.l) return n1.l < n2.l;
15     else if(n1.w != n2.w) return n1.w < n2.w;
16     return n1.d > n2.d;
17 }
18 
19 int main() {
20     long long n;
21     while(scanf("%I64d",&n) ) {
22         if(n == 0) break;
23         memset(dp, 0, sizeof(dp));
24         for(long long i = 1; i <= n; i++) {
25             scanf("%I64d %I64d %I64d %I64d",&node[i].l, &node[i].w, &node[i].h, &node[i].d);
26             if(node[i].l < node[i].w) swap(node[i].l, node[i].w);
27         }
28         sort(node + 1, node + 1 + n, cmp);
29         for(long long i = 1; i <= n; i++) {
30             dp[i] = node[i].h;
31         }
32         for(long long i = 1; i <= n; i++) {
33             for(long long j = 1; j < i; j++) {
34                 if(node[i].d == 0) {
35                     if(node[i].l >= node[j].l && node[i].w >= node[j].w) {
36                         dp[i] = max(dp[i], dp[j] + node[i].h);
37                     } 
38                 } else if(node[i].d == 1) {
39                     if((node[i].l >= node[j].l && node[i].w > node[j].w) || (node[i].l > node[j].l && node[i].w >= node[j].w)) {
40                         dp[i] = max(dp[i], dp[j] + node[i].h);
41                     }
42                 } else {
43                     if(node[i].l > node[j].l && node[i].w > node[j].w) {
44                         dp[i] = max(dp[i], dp[j] + node[i].h);
45                     }
46                 }
47             }
48         }
49         long long ans = 0;
50         for(long long i = 1; i <= n; i++) ans = max(ans, dp[i]);
51         printf("%I64d\n", ans);
52     }
53     return 0;
54 }
View Code

 

HDU4001To Miss Our Children Time【dp】

标签:des   style   blog   http   io   ar   color   os   sp   

原文地址:http://www.cnblogs.com/zhanzhao/p/4107914.html

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