HDU1069(KB12-C)
Monkey and Banana
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13837 Accepted Submission(s): 7282
Problem Description
The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height.
They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.
Input
representing the number of different blocks in the following data set. The maximum value for n is 30.
Each of the next n lines contains three integers representing the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.
Output
Sample Input
Sample Output
Source
//2017-03-14
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int N = ;
int n, dp[N*];//DAG模型,dp[i]表示从第i个箱子出发能够走的最大值
struct node
{
int x, y, z;
void setNode(int a, int b, int c){
this->x = a;
this->y = b;
this->z = c;
}
}box[N*]; int dfs(int i)
{
int& ans = dp[i];
if(ans)return ans;//记忆化搜索
ans = ;
for(int j = ; j < n*; j++)
{
if(box[i].x > box[j].x && box[i].y > box[j].y)
{
ans = max(ans, dfs(j));
}
}
ans += box[i].z;
return ans;
} int main()
{
int a, b, c, kase = ;
while(cin>>n && n)
{
int cnt = ;
memset(dp, , sizeof(dp));
for(int i = ; i < n; i++)
{
cin>>a>>b>>c;
box[cnt++].setNode(a, b, c);
box[cnt++].setNode(a, c, b);
box[cnt++].setNode(b, a, c);
box[cnt++].setNode(b, c, a);
box[cnt++].setNode(c, a, b);
box[cnt++].setNode(c, b, a);
}
for(int i = ; i < n*; i++)
dfs(i);
int ans = ;
for(int i = ; i < n*; i++)
if(dp[i] > ans)ans = dp[i];
cout<<"Case "<<++kase<<": maximum height = "<<ans<<endl;
} return ;
}
HDU1069(KB12-C)的更多相关文章
- 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(还是dp基础)
今天不想说太多废话-由于等下要写自己主动提交机. 不知道能不能成功呢? 题目的意思就是,一个猴子,在叠砖头 ...以下的要严格大于上面的.求叠起来最高能到多少- n非常少,n^2算法毫无压力-话说dp ...
随机推荐
- mysql日期时间函数使用总结
获取函数 mysql默认的时间格式: yyyy-MM-dd 或者 yyyy-MM-dd HH:mm:ss 1. Date() 返回日期部分, date('2018-02-14 17:03:04') ...
- 跟着刚哥深入学maven(通俗易懂)
前言:目前所有的项目都在使用maven,可是一直没有时间去整理学习,这两天正好有时间,好好的整理一下. 一.为什么使用Maven这样的构建工具[why] ① 一个项目就是一个工程 如果项目非常庞大,就 ...
- Linux链接脚本学习--lds(转)
Linux链接脚本学习--lds 一.概论 ld: GNU的链接器. 用来把一定量的目标文件跟档案文件链接在一起,并重新定位它们的数据,链接符号引用. 一般编译一个程序时,最后一步就是运行ld进行链接 ...
- Linux - 针对用户账号的常用操作
用户目录 除root用户外,其他默认的用户目录一般为/home/<user name>. 可以通过如下步骤修改默认用户目录 修改/etc/passwd文件中相应用户的路径信息 停止此用户的 ...
- POJ 2578
#include<iostream> #include<stdio.h> #include<vector> using namespace std; int mai ...
- webgl之3d动画
之前的几篇文章都是静态的,而这里主要介绍如何使物体动起来,并且学会使用性能监视器来监测性能. 而如果要让物体动起来,实际上我们是有两种方法的,第一种是让物体真的动起来,另外一种是让摄像机动起来这样物体 ...
- redmine设置user projects时无法delete的处理方法
对于user,当要在管理员界面处理其projects权限时,发现部分项目只有edit按钮,而部分项目还有一个delete按钮. “delete”,直接点击按钮即可删除对应project权限,表明该pr ...
- FactoryMethod工厂方法模式(创建型模式)
1.工厂方法模式解决的问题 现在有一个抽象的游戏设施建造系统,负责构建一个现代风格和古典风格的房屋和道路. 前提:抽象变化较慢,实现变化较快(不稳定) 整个抽象的游戏设施建造系统相对变化较慢,本例中只 ...
- 【转】Intellij IDEA使用总结
原文地址:http://totohust.iteye.com/blog/1035550 1. IDEA内存优化 先看看你机器本身的配置而配置. \IntelliJ IDEA 8\bin\idea.ex ...
- Vue + Element UI 实现权限管理系统 前端篇(一):搭建开发环境
技术基础 开发之前,请先熟悉下面的4个文档 vue.js2.0中文, 优秀的JS框架 vue-router, vue.js 配套路由 vuex,vue.js 应用状态管理库 Element,饿了么提供 ...