题意:

如今给你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. day02变量

    一. 什么是变量? 变量:在程序运行过程中,值会发生变化的量.(与之相对应的,常量就是在程序运行过程中,值不会发生变化的量).无论是变量还是常量,在创建时都会在内存中开辟一块空间,用于保存它的值. 二 ...

  2. Hadoop不同模式下关键配置属性

    Hadoop分为三种模式: 独立(或本地)模式. 伪分布模式. 全分布模式 不同模式下关键配置项及属性内容如下面表格所示 组件名称 配置的文件名 属性名称 独立模式 伪分布模式 全分布模式 Commo ...

  3. span文本自动换行

    .span{ word-wrap: break-word; word-break: break-all; overflow: hidden; }

  4. Url 简单讲解

    eg: http://sb.test.com/login?name=liming&password=twotigers 协议 http https ftp 域名 sb.test.com 则是域 ...

  5. 紫书 习题8-6 UVa 1611 (构造法)

    这道题和例题8-1相当的像. 例题8-1https://blog.csdn.net/qq_34416123/article/details/80112017 一开始我还以为用归并的思想, 用交换把局部 ...

  6. PatentTips - Method for network interface sharing among multiple virtual machines

    BACKGROUND Many computing systems include a network interface card (NIC) to provide for communicatio ...

  7. R语言适配问题集锦

    画图时的中文乱码问题 我这是Mac Yousemite 10.10.5,在两个地方遇到了中文乱码 1.使用wordcloud包绘制中文标签云时. library(wordcloud) mydata & ...

  8. zzulioj--1825-- 会长爱数学(模拟)

    1825: 会长爱数学 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 6  Solved: 2 SubmitStatusWeb Board Descr ...

  9. List exercise

    The slice operator can take a third argument that determines the step size, so t[::2] creates a list ...

  10. 28.STL常用算法

    #include <algorithm> 算法 常用版本 描述 返回Type std::find() find(_InIt _Fisrt,_InIt _Last, _Ty& _Va ...