题意:

如今给你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. [AHOI2013]差异 后缀自动机_Parent树

    题中要求: $\sum_{1\leqslant i < j \leq n } Len(T_{i}) +Len(T_{j})-2LCP(T_{i},T_{j})$ 公式左边的部分很好求,是一个常量 ...

  2. [AHOI2013]作业 莫队 树状数组

    #include<cmath> #include<cstdio> #include<algorithm> #include<string> #inclu ...

  3. BZOJ 3325 [SCOI2013]密码 (逆模拟Manacher+构造)

    题目大意:给你一个字符串每个位置和相邻两个位置为回文中心的最长回文串长度,让你构造一个合法的字典序最小的字符串 挺有意思的构造题 首先按照$Manacher$的思想还原$p$数组 定义$f_{ij}$ ...

  4. 入门python:《Python编程快速上手让繁琐工作自动化》中英文PDF+代码

    入门推荐学习<python编程快速上手>前6章是python的基础知识,通俗易懂地讲解基础,初学者容易犯错的地方,都会指出来.从第三章开始,每章都有一个实践项目,用来巩固前面所学的知识. ...

  5. keepalived的功能及DR模式搭建笔记

    一.HA集群中的相关术语 1.节点(node) 运行HA进程的一个独立主机,称为节点,节点是HA的核心组成部分,每个节点上运行着操作系统和高可用软件服务,在高可用集群中,节点有主次之分,分别称之为主节 ...

  6. 【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把序列生成的过程看成一颗树 会发现最后形成的是一颗二叉树. 每个二叉树上的节点就对应了序列中的一个数字. 如果我们把每个节点都往下投 ...

  7. NYIST 531 太空飞行计划

    太空飞行计划 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述        W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利 ...

  8. android将String转化为MD5的方法+一些String经常使用的方法

    public class StringUtils { public static String MD5Encode(String origin) { String resultString = nul ...

  9. 一入python深似海--python之道

    python社区不乏幽默.先来看"python之道"这首诗. 导入this包: import this 输出是一首诗,这首诗总结了Python的风格,能够指导Python程序猿的编 ...

  10. 设置linux session 编码

    设置linux session 编码 export LANG=zh_CN.utf-8