HDU 1069 Monkey and Banana 基础DP

题目链接:Monkey and Banana

大意:给出n种箱子的长宽高。每种不限个数。可以堆叠。询问可以达到的最高高度是多少。
要求两个箱子堆叠的时候叠加的面。上面的面的两维长度都严格小于下面的。

简单的DP,依然有很多地发给当时没想到。比如优先级,比如这么简单粗暴的选择。

 1 /*
 2  大意是。给出n种箱子的长宽高。每种不限个数。可以堆叠。询问可以达到的最高高度是多少。
 3  要求两个箱子堆叠的时候叠加的面。上面的面的两维长度都严格小于下面的。
 4
 5  样例:
 6  10 20 30
 7  10 20
 8  10 30
 9  20 30
10  可以摆放的方法:10 20
11                  20 30
12  高度:          30+10 = 40
13
14  /思路:把所有种类的箱子的每个面的两维长度都列出来。n<=30,那么,箱子的面个数<=90。然后按照要求来开始堆叠。
15  问题是。我应该怎么来找当前最符合条件的呢。从两维长度都最大的开始吗。下一个怎么对应呢。还是应该从面积最大的开始。可能性太多。
16  以上出自无厘头系列。
17  /
18
19  思路:给出一种箱子可以看做是三个箱子。(完全相同的两个面是不可能出现两次的。所以一个箱子最多会用三次、)。把所有的箱子按照先长后宽,从大到小排序。
20  然后(LIS。求最长递减子序列的思路。)dp[i] = j 表示从1到i的前i个(暂且当做从1开始)箱子里。在选第i个的前提下,得到的最大高度。
21 */
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <iostream>
26 #include <algorithm>
27 using namespace std;
28
29 struct Node {
30     int x, y, z;
31 }node[2100]; // 最多90个
32
33 bool cmp(Node a, Node b) {
34     if (a.x != b.x)
35         return a.x < b.x;
36     else return a.y < b.y;
37 }
38
39 int h[2100];
40
41 int main() {
42      int n;
43      int num = 0;
44      while(~scanf("%d", &n)) {
45         if (n == 0) break;
46         num++;
47         for (int j=0, i=0; j<n; ++j) {
48             int a, b, c;
49             scanf("%d%d%d", &a, &b, &c);
50             node[i].x = a, node[i].y = b, node[i].z = c;
51             node[i+1].x = a, node[i+1].y = c, node[i+1].z = b;
52             node[i+2].x = b, node[i+2].y = c, node[i+2].z = a;
53             i += 3;
54         }
55
56         for (int i=0; i<n*3; ++i) {
57             if (node[i].x < node[i].y) {
58                 int temp = node[i].y;
59                 node[i].y = node[i].x;
60                 node[i].x = temp;
61             }
62         }
63
64         sort(node, node+n*3, cmp);
65         int ans = -1;
66
67         for (int i=0; i<3*n; ++i) {
68             h[i] = node[i].z;
69             for (int j=0; j<i; ++j) {
70                 if (node[j].x < node[i].x && node[j].y < node[i].y) {
71                     h[i] = max(h[i], h[j]+node[i].z);
72                 }
73             }
74             ans = max(ans, h[i]);
75         }
76
77         printf("Case %d: maximum height = %d\n", num, ans);
78      }
79      return 0;
80 }

时间: 2024-10-05 05:06:04

HDU 1069 Monkey and Banana 基础DP的相关文章

HDU 1069 Monkey and Banana(DP 长方体堆放问题)

Monkey and Banana Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever

HDU 1069 Monkey and Banana dp 题解

HDU 1069 Monkey and Banana 题解 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种长方体,计算,最高能堆多高.要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽. 输入输出 开始一个数n,表示有多少种木块,木块的数量无限,然后接下来的n行,每行3个数,是木块的长宽高三个参量 输出使用这些在满足条件的情况下能够摆放的最大高度 解

[2016-03-30][HDU][1069][Monkey and Banana]

时间:2016-03-27 15:19:40 星期日 题目编号:[2016-03-30][HDU][1069][Monkey and Banana] 题目大意:给定n种积木无限个,问这些积木最大能叠多高,上面的积木长宽必须严格小于下面的积木 分析: dp[i]表示第i个积木在顶部时候的最大高度,那么dp[i] = max(dp[i],dp[j] + h[i]);?ji能放在j上面?ji能放在j上面 初始条件就是长宽最大的高度是它自己, #include <algorithm> #include

HDU 1069 Monkey and Banana (动规)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7248    Accepted Submission(s): 3730 Problem Description A group of researchers are designing an experiment to test the IQ of a

DP [HDU 1069] Monkey and Banana

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7854    Accepted Submission(s): 4051 Problem Description A group of researchers are designing an experiment to test the IQ of a

hdu 1069 Monkey and Banana (结构体排序,也属于简单的dp)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7770    Accepted Submission(s): 4003 Problem Description A group of researchers are designing an experiment to test the IQ of a

HDU 1069 Monkey and Banana(二维偏序LIS的应用)

---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13003    Accepted Submission(s): 6843 Problem Description A group of researchers are designing an experiment to te

HDOJ 1069 Monkey and Banana 【DP】

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8610 Accepted Submission(s): 4452 Problem Description A group of researchers are designing an experiment to test the IQ of a monke

HDU 1069 Monkey and Banana LCS变形

点击打开链接题目链接 Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7617    Accepted Submission(s): 3919 Problem Description A group of researchers are designing an experiment to test