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个的高度
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#define ll long long
#define pi 3.1415927
#define inf 0x3f3f3f3f
using namespace std;
struct node {
int x,y,z;
}a[];
bool cmp (node x, node y)
{
if (x.x==y.x)
return x.y<y.y;
return x.x<y.x;
}
int dp[];
int main ()
{
int n,m,i,t,sum,j=,k;
while(cin>>n)
{
j++;
if(n==)
break;
k=;
for(i=;i<n;++i)
{
int x,y,z;
cin>>x>>y>>z;
if(x==y==z)
a[k].x=x, a[k].y=y, a[k++].z=z;
else if (x==y)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=z, a[k].y=x, a[k++].z=y;
else if (x==z)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=y, a[k].y=x, a[k++].z=z;
else if (y==z)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=z, a[k].y=y, a[k++].z=x,
a[k].x=y, a[k].y=x, a[k++].z=z;
else
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=y, a[k].y=x, a[k++].z=z,
a[k].x=y, a[k].y=z, a[k++].z=x,
a[k].x=z, a[k].y=y, a[k++].z=x,
a[k].x=z, a[k].y=x, a[k++].z=y;
}
sort(a,a+k,cmp);
for(i=;i<k;++i)
dp[i]=a[i].z;
int maxs=;
for(i=;i<k;++i)
for(t=;t<i;++t)
{
if(a[i].x>a[t].x &&a[i].y>a[t].y){
dp[i]=max(dp[i],dp[t]+a[i].z);
maxs=max(maxs,dp[i]);
}
}
cout<<"Case "<<j<<": maximum height = "<<maxs<<endl;
} return ;
}
HDU 1069 Monkey and Banana (动态规划)的更多相关文章
- 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 ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1069 Monkey and Banana
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- neo4j常用cypher语句
阅读更多 1.删除带有关系的节点 a.先删除关系 match (n:Node)-[r:关系名称]-() where (n...条件) delete r b.删除节点 match (n:Node ...
- MySQL 07章_子查询
子查询就是查询中还可以嵌套其他的查询,通常是内层查询的结果作为外层查询的条件来使用 执行循序,自内向外依次执行 一.内层查询返回“单列单行”的结果 -- 1.查询宋江的出生日期 SELECT TIME ...
- Leetcode274.H-IndexH指数
原题的中文翻译不是很好,所以给出英文版. Given an array of citations (each citation is a non-negative integer) of a rese ...
- 数据库MySQL--联合查询
应用场景:当要查询的结果来自多个表,且多个表没有直接的连接关系,但查询的信息一致时 语法: 查询语句1 union(all) 查询语句2 union(all) ..... 注:多条查询语句的查询列数要 ...
- 5.从物理层到MAC层
第一层(物理层) 如何用两台电脑构成最小的局域网(LAN)? 网线的水晶头1.2和3.6脚分别起着收.发信号的作用,随意只要将水晶头做交叉线1-3.2-6交叉法,然后连接两台电脑.除了 ...
- undertow服务器
参考地址:http://undertow.io/undertow-docs/undertow-docs-1.3.0/index.html 1.引入相关jar <dependencies> ...
- yield支持的协程
#_author:来童星#date:2019/12/12def consumer(name): print("--->start...") while True: new_b ...
- PHP跨服务器提交数据
关于类似的问题,百度上一搜一大堆,这只是我自己实际用过的两个方法,不多BB直接上代码 1.第一种: 2.第二种 可以随意切换POST和GET提交方式
- Block的Retain Cycle的解决方法
一个使用Block语法的实例变量,在引用另一个实例变量的时候,经常会引起retain cycle.这个问题在使ASIHTTPRequest的block语法的时候会时不时的碰到.这个问题困扰了我这个小白 ...
- error LNK2001: unresolved external symbol _main解决办法(zz)
error LNK2001: unresolved external symbol _main解决办法 解决外部符号错误:_main,_WinMain@16,__beginthreadex -!t ...