hdu(1069)——Monkey and Banana(LIS变形)
题意:
如今给你n个石块,然后它由坐标来表示(x,y,z)。可是它能够有不同的方法,也就是说它的三个坐标能够轮换着来的。
石块的数量不限,可是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所能拼成的最大高度是多少。
思路:
由于坐标有多种情况。所以我们能够把每次的情况都存下去。
这里须要注意的是。在保存的时候,我们要保持x的坐标是大于y的。这样方便我们之后的排序。
然后就直接求最长递减子序列就好了。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define maxn 111
#define inf 99999999
int dp[maxn];
struct node{
int x,y,z,s;
}a[maxn];
bool cmp(node a,node b){
if(a.x!=b.x) return a.x>b.x;
else if(a.x==b.x) return a.y>b.y;
}
int main(){
int n;
int j=1;
while(~scanf("%d",&n)){
if(n==0) break;
int t=0;
for(int i=0;i<n;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
a[t].x=x>y?x:y; a[t].y=x>y? y:x; a[t].z=z;
t++;
a[t].x=y>z?y:z; a[t].y=y>z?z:y; a[t].z=x;
t++;
a[t].x=x>z?x:z; a[t].y=x>z?z:x; a[t].z=y;
t++;
}
sort(a,a+t,cmp);
memset(dp,0,sizeof(dp));
dp[0]=a[0].z;
int ans=-1;
for(int i=0;i<t;i++){
int res=0;
for(int j=0;j<i;j++){
if((a[i].x<a[j].x&&a[i].y<a[j].y)||(a[i].x<a[j].y&&a[i].y<a[j].x)){
res=max(res,dp[j]);
}
}
dp[i]=res+a[i].z;
ans=max(ans,dp[i]);
}
printf("Case %d: maximum height = %d\n",j++,ans);
}
}
尽管题目简单。可是这道题也是由我自己想出来的呢,由易到难的练下去吧!
我相信我自己的努力,在不久的以后一定能尝到AC难题的喜悦!
@全部学习dp的人,加油!!
。
hdu(1069)——Monkey and Banana(LIS变形)的更多相关文章
- 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(二维偏序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 基础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 ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- 创建一个 Django 项目
一. 创建项目 其中: 确认项目是否创建成功: 在 manage.py 目录上运行 python manage.py runserver server 启动后,在浏览器访问 http://127.0. ...
- TP5 分页类,自定义样式
结合X-admin 后台框架 在做项目,为了保持分页风格的一致,所以需要自定义 一个分页类. 一.在项目的 extend 目录,创建 cus 目录 二.创建 Page 分页类,代码如下 <?ph ...
- chrome 获取移动端页面元素信息
一:背景在使用appium进行app端自动化测试的时候,一般使用的是uiautomatorviewer来给页面元素做定位.但如果遇到页面元素类型是webview的时候,则只能定位整个页面,而不能更进一 ...
- SASS 使用(vs code)
二.在vs code中编译sass 1.在拓展商店里搜索“easy sass”,并安装,安装成功后点重新加载. 2.接下来进行配置: 在 vs code 菜单栏依次点击“文件 首选项 设置”,打开 s ...
- PHP SOAP 教程
一.SoapServer 服务器 1.__construct 作用:创建 SoapServer 对象 用法:__construct ( mixed wsdl [, array options] ) 参 ...
- /etc/rc.d/rc.sysinit
[root@web02 ~]# ls /etc/rc.d/rc.sysinit /etc/rc.d/rc.sysinit [root@web02 ~]# [root@web02 ~]# ls /etc ...
- R语言学习(一)前言
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/49768161 R是一个有着统计分析功能 ...
- mysql死锁-查询锁表进程-分析锁表原因
查询锁表进程: 1.查询是否锁表 show OPEN TABLES where In_use > 0; 2.查询进程 show processlist 查询到相对应的进程===然 ...
- Google笔试(2015年8月)
华电北风吹 天津大学认知计算与应用重点实验室 日期:2015/8/21 这三道题目的PDF能够在这里下载 https://github.com/ncepuzhengyi/jobHuntingExam/ ...
- [WebGL入门]十五,为多边形涂抹颜色(顶点颜色的指定)
注:文章译自http://wgld.org/.原作者杉本雅広(doxas),文章中假设有我的额外说明,我会加上[lufy:].另外.鄙人webgl研究还不够深入.一些专业词语.假设翻译有误.欢迎大家指 ...