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 ...
随机推荐
- 路飞学城Python-Day18
[1.编程范式] 1.面向过程编程 2.面向对象编程 [2.面向过程编程] 面向过程:核心就是过程 什么是过程? 过程指的是解决问题的步骤,先做什么,在作什么,面向过程就像是设计一个流水线,是一种 ...
- [NOIP2015普及组]推销员
题目:洛谷P2672.codevs5126.Vijos P1977 题目大意:有个推销员要去推销,要你求他推销1~n户人家分别最多花多少“疲劳值”.具体见题目. 解题思路:如果用$O(n^2)$做的话 ...
- jQuery第三课 点击按钮 弹出层div效果
jQuery 事件方法 事件方法会触发匹配元素的事件,或将函数绑定到所有匹配元素的某个事件. 触发实例: $("button#demo").click() 上面的例子将触发 id= ...
- 国庆 day 1 下午
一道图论好题(graph) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图, ...
- Unity渲染
我们先大概了解一下对渲染的优先级有影响的几个因素 1.Camera.Depth 不同相机的深度,在渲染顺序的优先度里面是最高的,Depth越大,渲染的图像越靠前 2.Render.SortingOrd ...
- Linux之我最常用的20条命令
Linux之我最常用的20条命令 玩过 Linux的人都会知道, Linux中的命令的确是非常多,但是玩过 Linux的人也从来不会因为 Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的 ...
- opecv2 MeanShift 使用均值漂移算法查找物体
#if !defined OFINDER #define OFINDER #include <opencv2\core\core.hpp> #include <opencv2\img ...
- 转载-让PIP源使用国内镜像,提升下载速度和安装成功率
让PIP源使用国内镜像,提升下载速度和安装成功率. 对于Python开发用户来讲,PIP安装软件包是家常便饭.但国外的源下载速度实在太慢,浪费时间.而且经常出现下载后安装出错问题.所以把PIP安装源替 ...
- nyoj--311--完全背包(动态规划,完全背包)
完全背包 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 直接说题意,完全背包定义有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的体积是c,价值是w. ...
- C# Hook
C# Hook原理及EasyHook简易教程 前言 在说C# Hook之前,我们先来说说什么是Hook技术.相信大家都接触过外挂,不管是修改游戏客户端的也好,盗取密码的也罢,它们都是如何实现的呢? 实 ...