一组研究人员正在设计一项实验,以测试猴子的智商。他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子。如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉。
 
研究人员有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. mqtt.mini.js 使用

    html文件里直接调用 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  2. StudentManagerSSM

    web.xml              StudentManagerSSM.rar <?xml version="1.0" encoding="UTF-8&quo ...

  3. 牛客跨年AK场-小sum的假期安排

    链接:https://ac.nowcoder.com/acm/contest/3800/G来源:牛客网 题目描述 小 sun 非常喜欢放假,尤其是那种连在一起的长假,在放假的时候小 sun 会感到快乐 ...

  4. mcast_block_source函数

    #include <errno.h> #include <sys/socket.h> #define SA struct sockaddr int mcast_block_so ...

  5. Tomcat访问控制及站点部署(以WAR包形式上传)!(重点)

    访问控制 首先安装好jdk以及apache-tomcat并能访问tomcat网页 点击server status了解服务状态会报403的错误 第一步:修改user.xml配置文件 [root@loca ...

  6. Centos610无桌面安装Docker-安装

    1.必备环境 设定docker源yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.rep ...

  7. vue通过get方法下载java服务器excel模板

    vue方法 handleDownTemplateXls(fileName){ if(!fileName || typeof fileName != "string"){ fileN ...

  8. php cli 下 php.ini 配置

    // 查看phpcli 模式下 扩展 php -m // 查看php cli 版本 php -v 查看命令行的ini路径,命令行下运行 php --ini Loaded Configuration F ...

  9. NSObject类的API介绍

    这篇文章围绕的对象就是NSObject.h文件,对声明文件中的属性.方法进行必要的“翻译”. 该文件大致由两部分组成:NSObject协议和NSObject类. (一)NSObject协议 - (BO ...

  10. iOS中常用的手势

    --前言 智能手机问世后的很长一段时间,各大手机厂商都在思考着智能手机应该怎么玩?也都在尝试着制定自己的一套操作方式.直到2007年乔布斯发布了iPhone手机,人们才认识到智能手机就应该这样玩. 真 ...