题意:

如今给你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变形)的更多相关文章

  1. 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 ...

  2. HDU 1069 Monkey and Banana dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

  3. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

  4. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 1069 Monkey and Banana 基础DP

    题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...

  8. hdu 1069 Monkey and Banana

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU 1069 Monkey and Banana(动态规划)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  10. HDU 1069 Monkey and Banana(DP 长方体堆放问题)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

随机推荐

  1. 【BZOJ4005】[JLOI2015]骗我呢

    题意: Alice和Bob在经过了数学的洗礼之后,不再喜欢玩对抗游戏了,他们喜欢玩合作游戏.现在他们有一个n×m的网格,Alice和Bob要在一定规则下往网 格里填数字,Alice和Bob都是聪明绝顶 ...

  2. vue-cli3+typescript+路由懒加载报错问题

    vue-cli3的版本是3.4.1 出现的情况是网页显示正常,但是终端一直提示找不到模块: 如果去掉路由懒加载的方式,就没有报错: 原因是以前我们习惯直接写文件名而不加后缀, 现在使用ts时就需要写v ...

  3. 数组的常用方法 Array;

    数组: 1,arr.join();//返回默认由逗号隔开的一个字符串,传参则返回所传参数隔开的一个字符串; 2,arr.push();//往数组最后添加数据,返回新的数组的length,这个方法将改变 ...

  4. Tarjan 割点割边【模板】

    #include <algorithm> #include <cstring> #include <cstdio> using namespace std; +); ...

  5. asp.net C# 获取网页源代码的几种方式

    1 方法 System.Net.WebClient aWebClient = new System.Net.WebClient(); aWebClient.Encoding = System.Text ...

  6. unix中文件I/O

    在unix中可用的文件I/O函数包含打开文件,读文件,写文件等. Unix系统中的大多数文件I/O须要用到5个函数:open,read,write,lseek,close. 这里要说明的是read,w ...

  7. nodejs微服务健康检查方案

    1. 前言 针对目前云平台方案,因为网络.主机状态等诸多因素,单台主机上的服务出现问题的几率大大增加.这就要求我们能够监控每台主机.每个微服务实例的健康状态.因此对于nodejs相关项目需要做相关的微 ...

  8. 威胁报告:mDNS 反射式 DDoS 攻击

    威胁报告:mDNS 反射式 DDoS 攻击 转自:https://www.akamai.com/cn/zh/about/our-thinking/threat-advisories/akamai-md ...

  9. [COI2007] [luogu P1823] Patrik 音乐会的等待 解题报告 (单调栈)

    题目链接:https://www.luogu.org/problemnew/show/P1823 题目: N个人正在排队进入一个音乐会.人们等得很无聊,于是他们开始转来转去,想在队伍里寻找自己的熟人. ...

  10. js运算符单竖杠“|”与“||”的用法和作用介绍

    在js开发应用中我们通常会碰到“|”与“||”了,那么在运算中“|”与“||”是什么意思呢?   在js整数操作的时候,相当于去除小数点,parseInt.在正数的时候相当于Math.floor(), ...