hdu1069
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
class Data
{
public:
int S, Height;
int upl, uph;
};
Data Da[100];
int n;
int dp[100];
int cmp(const Data &a, const Data &b) //按照面积最大或高度最高排序
{
if(a.S != b.S)
return a.S > b.S;
else
return a.Height > b.Height;
}
int main()
{
// freopen("data.txt", "r", stdin);
int i, j, k, Case = 1;
int a, b, c;
while(cin >> n && n)
{
k = 0;
memset(dp, 0, sizeof(dp));
for(i = 0; i < n; i++) //计算每一个面的面积,以及顶面的长宽以及高度
{
cin >> a >> b >> c;
Da[k].S = a * b; Da[k].upl = a > b ? a : b; Da[k].uph = a > b ? b : a;
Da[k++].Height = c;
Da[k].S = a * c; Da[k].upl = a > c ? a : c; Da[k].uph = a > c ? c : a;
Da[k++].Height = b;
Da[k].S = b * c; Da[k].upl = b > c ? b : c; Da[k].uph = b > c ? c : b;
Da[k++].Height = a;
}
sort(Da, Da + k, cmp); //排序
int ans = 0;
for(i = 0; i < k; i++) //动态规划
{
dp[i] = Da[i].Height;
for(j = 0; j < i; j++)
{
if(Da[i].S < Da[j].S && Da[i].upl < Da[j].upl && Da[i].uph < Da[j].uph) //判断是否符合
{
dp[i] = dp[i] > dp[j] + Da[i].Height ? dp[i] : dp[j] + Da[i].Height;
}
}
if(ans < dp[i]) //最大高度
ans = dp[i];
}
cout << "Case " << Case++ << ": maximum height = " << ans << endl;
}
return 0;
}
hdu1069的更多相关文章
- HDU1069 Monkey and Banana
HDU1069 Monkey and Banana 题目大意 给定 n 种盒子, 每种盒子无限多个, 需要叠起来, 在上面的盒子的长和宽必须严格小于下面盒子的长和宽, 求最高的高度. 思路 对于每个方 ...
- HDU-1069 Monkey and Banana DAG上的动态规划
题目链接:https://cn.vjudge.net/problem/HDU-1069 题意 给出n种箱子的长宽高 现要搭出最高的箱子塔,使每个箱子的长宽严格小于底下的箱子的长宽,每种箱子数量不限 问 ...
- ACM-经典DP之Monkey and Banana——hdu1069
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- HDU1069:Monkey and Banana(DP+贪心)
Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T ...
- hdu1069(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 分析: 每种石头有六种方法,那么等效为:有6*n种石头. 根据x和y排序(要保证相应的x.y总有 ...
- HDU1069 最长上升子序列
emm....矩形嵌套 还记得吗....就是它... 直接贴代码了.... import java.util.ArrayList; import java.util.Arrays; import ja ...
- hdu1069线性dp
/* dp[i]:取第i个方块时最多可以累多高 */ #include<bits/stdc++.h> using namespace std; struct node{ int x,y,z ...
- HDU-1069.MonkeyandBanana(LIS)
本题大意:给出n个长方体,每种长方体不限量,让你求出如何摆放长方体使得最后得到的总高最大,摆设要求为,底层的长严格大于下层的长,底层的宽严格大于下层的宽. 本题思路:一开始没有啥思路...首先应该想到 ...
- HDU1069(KB12-C)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1069(还是dp基础)
今天不想说太多废话-由于等下要写自己主动提交机. 不知道能不能成功呢? 题目的意思就是,一个猴子,在叠砖头 ...以下的要严格大于上面的.求叠起来最高能到多少- n非常少,n^2算法毫无压力-话说dp ...
随机推荐
- ios9 3dtouch 博客
http://my.oschina.net/u/2340880/blog/511509#OSC_h3_3
- HDU 之 I Hate It
I Hate It Time Limit ...
- 算法(Algorithms)第4版 练习 2.1.4
E A S Y Q U E S T I O N A E S Y Q U E S T I O N A E S Y Q U E S T I O N A E S Y Q U E S T I O N A E ...
- JAVA- 数据库连接池原理
第一次Java程序要在MySQL中执行一条语句,那么就必须建立一个Connection对象,代表了与MySQL数据库的连接通过直接发送你要执行的SQL语句之后,就会调用Connection.close ...
- 在解析XML时要注意解析元素和解析标签属性的区别
解析元素时: Sting str = ele.elementText("name"); 而解析标签属性时: String key = ele.attributeValue(&quo ...
- POJ1363 Rails 验证出栈序列问题
题目地址: http://poj.org/problem?id=1363 此题只需验证是否为合法的出栈序列. 有两个思路: 1.每个已出栈之后的数且小于此数的数都必须按降序排列.复杂度O(n^2),适 ...
- Selenium-js弹窗浮层
学习过js的小伙伴会发现,我们在一些实例中用到了alert()方法.prompt()方法.prompt()方法,他们都是在屏幕上弹出一个对话框,并且在上面显示括号内的内容,使用这种方法使得页面的交互性 ...
- python-管理MySQL之ConfigParser模块
1.拷贝2.7版本的ConfigParser.py模块支持无值解析 cp /usr/local/src/Python-2.7.5/Lib/ConfigParser.py /usr/lib/python ...
- codeforces 655C C. Enduring Exodus(二分)
题目链接: C. Enduring Exodus time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Poj 2299 Ultra-QuickSort(归并排序求逆序数)
一.题意 给定数组,求交换几次相邻元素能是数组有序. 二.题解 刚开始以为是水题,心想这不就是简单的冒泡排序么.但是毫无疑问地超时了,因为题目中n<500000,而冒泡排序总的平均时间复杂度为, ...