HDU 1069 Monkey and Banana (动态规划)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069

简单记录一下

思路:把长方体的各种摆法都存到数组里面,然后按照长宽排序,再dp即可

转移方程 dp[i]=max(dp[i],dp[t]+a[i].z)  //dp里存的是高度,a[i].z是第i个的高度
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <string>
 6 #include <stack>
 7 #include <queue>
 8 #include <cmath>
 9 #define ll long long
10 #define pi 3.1415927
11 #define inf 0x3f3f3f3f
12 using namespace std;
13 struct node {
14     int x,y,z;
15 }a[200];
16 bool cmp (node x, node y)
17 {
18     if (x.x==y.x)
19         return x.y<y.y;
20     return x.x<y.x;
21 }
22 int dp[200];
23 int main ()
24 {
25     int n,m,i,t,sum,j=0,k;
26     while(cin>>n)
27     {
28         j++;
29         if(n==0)
30             break;
31         k=0;
32         for(i=0;i<n;++i)
33         {
34             int x,y,z;
35             cin>>x>>y>>z;
36             if(x==y==z)
37                 a[k].x=x, a[k].y=y, a[k++].z=z;
38             else if (x==y)
39                 a[k].x=x, a[k].y=y, a[k++].z=z,
40                 a[k].x=x, a[k].y=z, a[k++].z=y,
41                 a[k].x=z, a[k].y=x, a[k++].z=y;
42             else if (x==z)
43                 a[k].x=x, a[k].y=y, a[k++].z=z,
44                 a[k].x=x, a[k].y=z, a[k++].z=y,
45                 a[k].x=y, a[k].y=x, a[k++].z=z;
46             else if (y==z)
47                 a[k].x=x, a[k].y=y, a[k++].z=z,
48                 a[k].x=z, a[k].y=y, a[k++].z=x,
49                 a[k].x=y, a[k].y=x, a[k++].z=z;
50             else
51                 a[k].x=x, a[k].y=y, a[k++].z=z,
52                 a[k].x=x, a[k].y=z, a[k++].z=y,
53                 a[k].x=y, a[k].y=x, a[k++].z=z,
54                 a[k].x=y, a[k].y=z, a[k++].z=x,
55                 a[k].x=z, a[k].y=y, a[k++].z=x,
56                 a[k].x=z, a[k].y=x, a[k++].z=y;
57         }
58         sort(a,a+k,cmp);
59         for(i=0;i<k;++i)
60             dp[i]=a[i].z;
61         int maxs=0;
62         for(i=1;i<k;++i)
63             for(t=0;t<i;++t)
64         {
65             if(a[i].x>a[t].x &&a[i].y>a[t].y){
66                 dp[i]=max(dp[i],dp[t]+a[i].z);
67                 maxs=max(maxs,dp[i]);
68             }
69         }
70         cout<<"Case "<<j<<": maximum height = "<<maxs<<endl;
71     }
72
73
74     return 0;
75 }

原文地址:https://www.cnblogs.com/blowhail/p/11951861.html

时间: 2024-07-29 18:35:36

HDU 1069 Monkey and Banana (动态规划)的相关文章

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(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 (动规)

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

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

HDU 1069 Monkey and Banana 基础DP

题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. 简单的DP,依然有很多地发给当时没想到.比如优先级,比如这么简单粗暴的选择. 1 /* 2 大意是.给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 3 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. 4 5 样例: 6 10 20 30 7 10

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

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

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