HDU 1069 Monkey and Banana DP LIS
http://acm.hdu.edu.cn/showproblem.php?pid=1069
题目大意
一群研究员在研究猴子的智商(T T禽兽啊,欺负猴子!!!),他们决定在房顶放一串香蕉,并且给猴子n种砖块。
砖块长宽高分别为xyz,每一种可以取任意个,并且他们可以随意的摆放。
然后要求堆叠起来的砖块上面的必须严格小于下面的。
求最大可以堆叠的高度。
思路:
转化为LIS问题,把每一种摆放方法如(10,20,30)(可以以20 30 作为底,10作为高)都放进数组,然后就是求最大上升子序列。
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=200;
struct data
{
int x,y;
int h;
}a[MAXN];
bool operator <(const data &a,const data &b)
{
return a.x<b.x;
}
int main()
{
int n;
int kase=1;
while(scanf("%d",&n),n)
{
int len=0;
int x,y,z;
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&x,&y,&z);
a[len].x=x; a[len].y=y; a[len++].h=z;
a[len].x=x; a[len].y=z; a[len++].h=y;
a[len].x=y; a[len].y=x; a[len++].h=z;
a[len].x=y; a[len].y=z; a[len++].h=x;
a[len].x=z; a[len].y=x; a[len++].h=y;
a[len].x=z; a[len].y=y; a[len++].h=x;
} sort(a,a+len); int dp[MAXN];
for(int i=0;i<len;i++)
{
dp[i]=a[i].h;
int temp=0;
for(int j=0;j<i;j++)
{
if(a[i].x>a[j].x && a[i].y >a[j].y)
temp=max(temp,dp[j]);
}
dp[i]+=temp;
}
int ans=0;
for(int i=0;i<len;i++)
ans=max(ans,dp[i]); printf("Case %d: maximum height = %d\n",kase++,ans);
} return 0;
}
HDU 1069 Monkey and Banana DP LIS的更多相关文章
- HDU 1069 Monkey and Banana DP LIS变形题
http://acm.hdu.edu.cn/showproblem.php?pid=1069 意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定. 你可以选任意两 ...
- HDU 1069 monkey an banana DP LIS
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription 一组研究人员正在 ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- 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 Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana(LIS最长上升子序列)
B - LIS Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descripti ...
- hdu(1069)——Monkey and Banana(LIS变形)
题意: 如今给你n个石块,然后它由坐标来表示(x,y,z).可是它能够有不同的方法,也就是说它的三个坐标能够轮换着来的. 石块的数量不限,可是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所 ...
- 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(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
随机推荐
- 如何优雅的写UI——(3)添加MFC选项卡
窗体创建完成,接下来我们讲讲控件的使用 首先在CFormView窗体下选项卡的成员变量,这里我选择MFC下的选项卡类库:CMFCTabCtrl class CtabView : public CFor ...
- NO.1 You must restart adb and Eclipse多种情形分析与解决方式
一:错误提示 The connection to adb is down, and a severe error has occured. You must restart adb and Eclip ...
- 存储控制器和SDRAM 实验
S3C2440 存储控制器(memory controller)提供了訪问外部设备所需的信号,这是一种通过总线形式来訪问扩展的外设. S3C2440 的存储器控制器有下面的特性: 支持小字节序.大字 ...
- 【MySQL】常见错误与经常使用命令的集锦
[背景介绍] 在使用SQL Server数据库期间,想必大家一定都有过解决各种问题的经历了.非常多时候,都会在大家的博客中看到问题与解决方式. 如今开发使用的是MySQL数据库.如今来看,发现 ...
- Problem C: Celebrity Split
题目描写叙述 Problem C: Celebrity Split Jack and Jill have decided to separate and divide their property e ...
- 6lession-基本数据类型
因为自己是根据网上教程学习的,所以以下内容参考自 http://www.w3cschool.cc/python/python-variable-types.html python支持物种数据类型,分别 ...
- golang md5
package main import ( "crypto/md5" "encoding/hex" "fmt" "io" ...
- SqlParameter的用法
SqlParameter的用法 关于Sql注入的基本概念,相信不需多说,大家都清楚,经典的注入语句是' or 1=1--单引号而截断字符串,“or 1=1”的永真式的出现使得表的一些信息被暴露出来,如 ...
- mysql数据库忘记密码时如何修改(转)
当我们忘记mysql数据库密码时我们就无法正常进入数据库,也就无法修改密码,那么这时该怎么修改密码呢,这里教大家一个简单常用修改密码的方式. (如果图简单快速修改密码的话,直接跳过查询步骤,依照图上执 ...
- Mine Vison base on VC++ and procilica Gige Vison SDK
This is my first vision base on VC++6.0. I am so happy to record this time i succesfully create it b ...