HDU-1069 Monkey and Banana DAG上的动态规划
题目链接:https://cn.vjudge.net/problem/HDU-1069
题意
给出n种箱子的长宽高
现要搭出最高的箱子塔,使每个箱子的长宽严格小于底下的箱子的长宽,每种箱子数量不限
问最高可以搭出多高
思路
有向无环图(DAG)上的动规
想象有一个图,每个节点表示一种箱子,每个边代表可以落在一块的关系
递归的找max即可
$ dp(i)=max(dp(j)+h(i) | (i, j) \in E) $
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Box{
int x, y, z;
Box(int x=0, int y=0, int z=0):
x(x),y(y),z(z) {}
}box[200];
int n, data[200];
int dp(int idx){
if (data[idx]!=-1) return data[idx];
data[idx]=box[idx].z;
for (int i=0; i<n; i++){
if (i==idx || box[i].x>=box[idx].x || box[i].y>=box[idx].y) continue;
data[idx]=max(data[idx], dp(i)+box[idx].z);
}return data[idx];
}
int main(void){
int cnt=0;
while (scanf("%d", &n)==1 && n){
memset(data, -1, sizeof(data));
for (int i=0, x, y, z; i<n; i++){
scanf("%d%d%d", &x, &y, &z);
box[6*i+0]=Box(x, y, z); box[6*i+1]=Box(x, z, y);
box[6*i+2]=Box(y, z, x); box[6*i+3]=Box(y, x, z);
box[6*i+4]=Box(z, x, y); box[6*i+5]=Box(z, y, x);
}n*=6;
int max;
for (int i=0; i<n; i++)
if (max<dp(i) || i==0) max=dp(i);
printf("Case %d: maximum height = %d\n", ++cnt, max);
}
return 0;
}
| Memory | Length | Lang | Submitted |
|---|---|---|---|
| 1512kB | 1041 | G++ | 2018-02-16 03:34:42 |
HDU-1069 Monkey and Banana DAG上的动态规划的更多相关文章
- 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——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 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 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...
- 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(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- POJ 3299 模拟
水题,但是WA了一屏--- swap的时候忘了把读入的数字也swap了---------..[尴尬] // by SiriusRen #include <cmath> #include & ...
- NPOI简单的给某个单元格字体设置颜色
参考文档有: https://www.cnblogs.com/gossip/p/4307486.html https://bbs.csdn.net/topics/391042064?page=1 效果 ...
- MySQL学习(五)——使用JDBC完成用户表CRUD的操作
通过案例我们发现“获得连接”和“释放资源”两次代码将在之后的增删改查所有功能中都存在,开发中遇到此种情况,将采用工具类的方法进行抽取,从而达到代码的重复利用. 1.使用properties配置文件 开 ...
- HDU 3584 Cube 【 三维树状数组 】
题意:还是那篇论文里面讲到的,三维树状数组http://wenku.baidu.com/view/1e51750abb68a98271fefaa8画个立方体出来对照一下好想一点 #include< ...
- HDU 1548 A strange lift【BFS】
题意:给出一个电梯,给出它的层数f,给出起点s,终点g,以及在每一层能够上或者下w[i]层,问至少需要按多少次按钮到达终点. 和POJ catch that cow一样,直接用了那一题的代码,发现一直 ...
- CorelDRAW X6低价再次冲破底线
平时我们看到的标志设计.杂志排版.产品商标.插图描画......这些都是设计师们使用CorelDRAW设计而来.如今CorelDRAW已经成为每个设计师必装的软件,从12年发布CorelDRAW X6 ...
- Day92
# session:用于保存客户端历史访问的信息# BeautifulSoup是一个模块,该模块用于接收一个HTML或XML字符串,然后将其进行格式化,# 之后遍可以使用他提供的方法进行快速查找指定元 ...
- 微信小程序微信支付的一些坑
使用的是Node.js作为后端 统一下单: appid:这里的appid是调起微信支付的appid mch_id:商户号,需要注意的是商户号要与appid对应 nonce_str:Math.rando ...
- Docker yum 安装
[liwm@Eren ~]$ sudo su[root@Eren liwm]# yum install -y docker 已加载插件:fastestmirror, langpacks, prod ...
- 紫书 例题8-4 UVa 11134(问题分解 + 贪心)
这道题目可以把问题分解, 因为x坐标和y坐标的答案之间没有联系, 所以可以单独求两个坐标的答案 我一开始想的是按照左区间从小到大, 相同的时候从右区间从小到大排序, 然后WA 去uDebug找了数据 ...