一组研究人员正在设计一项实验,以测试猴子的智商。他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子。如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉。
 
研究人员有n种类型的砖块,每种类型的砖块都有无限个。第i块砖块的长宽高分别用xi,yi,zi来表示。 同时,由于砖块是可以旋转的,每个砖块的3条边可以组成6种不同的长宽高。
 
在构建塔时,当且仅当A砖块的长和宽都分别小于B砖块的长和宽时,A砖块才能放到B砖块的上面,因为必须留有一些空间让猴子来踩。
 
你的任务是编写一个程序,计算猴子们最高可以堆出的砖块们的高度。

Input

输入文件包含多组测试数据。
每个测试用例的第一行包含一个整数n,代表不同种类的砖块数目。n<=30.
接下来n行,每行3个数,分别表示砖块的长宽高。
当n= 0的时候,无需输出任何答案,测试结束。

Output对于每组测试数据,输出最大高度。格式:Case 第几组数据: maximum height = 最大高度Sample Input

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342 
 
思路:题意说无限砖头,但限制了长宽以后,将每一块砖头的6种加入候选,变成了有限制类型的01背包问题,dp[i]表示以i为最底层能到达的最大高度,其转移方程为dp[i] = max(dp[i], dp[j]+high[i])(j为满足长宽小于i的砖头)
const int maxm = ;

struct Node {
int x, y, z;
bool operator<(const Node &a) const {
return x < a.x || (x == a.x && y < a.y);
}
} Nodes[maxm]; int dp[maxm]; int main() {
ios::sync_with_stdio(false), cin.tie();
int n, t1, t2, t3, cnt, kase = ;
while(cin >> n && n) {
cnt = ;
for(int i = ; i <= n; ++i) {
cin >> t1 >> t2 >> t3;
Nodes[++cnt] = Node{t1, t2, t3};Nodes[++cnt] = Node{t2, t3, t1};Nodes[++cnt] = Node{t3, t1, t2};
Nodes[++cnt] = Node{t1, t3, t2};Nodes[++cnt] = Node{t2, t1, t3};Nodes[++cnt] = Node{t3, t2, t1};
}
sort(Nodes+, Nodes++cnt);
memset(dp, , sizeof(dp));
for(int i = ; i <= cnt; ++i) {
dp[i] = Nodes[i].z;
for(int j = ; j < i; ++j)
if(Nodes[i].x > Nodes[j].x && Nodes[i].y > Nodes[j].y)
dp[i] = max(dp[i], dp[j]+Nodes[i].z);
}
int ans = -;
for(int i = ; i <= cnt; ++i) ans = max(ans, dp[i]);
cout << "Case " << ++kase << ": maximum height = " << ans << "\n";
}
return ;
}

Day9 - F - Monkey and Banana HDU - 1069的更多相关文章

  1. (最大上升子序列)Monkey and Banana -- hdu -- 1069

    http://acm.hdu.edu.cn/showproblem.php?pid=1069      Monkey and Banana Time Limit:1000MS     Memory L ...

  2. (动态规划 最长有序子序列)Monkey and Banana --HDU --1069

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1069 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  3. Monkey and Banana HDU - 1069 有点像背包,又像最长上升序列

    #include<iostream> #include<algorithm> #include<cstring> #include<vector> us ...

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

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)

    HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...

  7. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

  8. hdu 1069 动规 Monkey and Banana

     Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  9. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. Python爬虫:urllib库的基本使用

    请求网址获取网页代码 import urllib.request url = "http://www.baidu.com" response = urllib.request.ur ...

  2. python 中的 int() 与 round

    int(x):向下取整 round(x):超过 .5 则向上取整,否则向下取整

  3. 案例:WLC HA主WLC进入维护模式

    案例场景: 如图所示,7609-1和7609-2分别是网络中的核心设备,起了HSRP,7609-1连接的是WLC-1,,7609-2连接的是WLC-2,WLC1和WLC2的RP口相互连接. WLC的管 ...

  4. Cisco AP-如何调整LAP信道

    GUI方法: CLI的方法:根据对应的接口去调整信道,信道带宽,传输功率等信息吧.(Cisco Controller) >config slot 0 antenna Configures the ...

  5. 【CSS 】js操作css

    对设置和移除所有 <p> 元素的 "main" 类进行切换: $("button").click(function(){ $("p&quo ...

  6. 树莓派4B踩坑指南 - (10)安装坚果云(更新:暂不支持)

    191209更新: 根据坚果云用户支持(helpdesk@nutstore.net)的官方回复,客户端不支持arm,所以本篇后续内容可以不用看了.. 原文如下: "您好,客户端似乎不支持ar ...

  7. nyoj 100

    怒刷水题... AC代码: #include <stdio.h> int main() { int x,t,count; scanf("%d",&t); whi ...

  8. python2.7 安装 Scipy

    Numpy.scikit-learn可以直接 pip install xxx 但Scipy不能,在官网找到了安装方法: python -m pip install --user numpy scipy ...

  9. uniGUI之通过URL控制参数(25)

    通过URL代入参数,在代码中读取,如: http://localhost:8077/?ServerPort=212&&ServerIP=192.168.31.12 procedure ...

  10. PTA的Python练习题(七)

    不知不觉一个星期过去了,继续从 第3章-12 求整数的位数及各位数字之和 开始做题 1. 我原来想用题目漏洞做题的,不过想想还是算了自己写个完整的: a=int(input()) b=len(str( ...