HDU4001To Miss Our Children Time【dp】

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

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了  后面的只会被前面的状态所决定

代码:

 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值