hdu 1069 Monkey and Banana (最长上升子序列)

http://acm.hdu.edu.cn/showproblem.php?pid=1069

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct Node
{
  int a,b,c,dp;
};
Node node[3000];
int cmp(Node x,Node y)
{
  if(x.a==y.a) return x.b<y.b;
  return x.a<y.a;
}

int main()
{
  int n;
  int i,j,k;
  int a,b,c;
  int cas=1;
  while(scanf("%d",&n),n)
  {
    for(i=1;i<=6*n;i++)
    {
      scanf("%d%d%d",&a,&b,&c);
      node[i].a=a;node[i].b=b;node[i].dp=node[i].c=c;i++;
      node[i].a=a;node[i].b=c;node[i].dp=node[i].c=b;i++;
      node[i].a=b;node[i].b=a;node[i].dp=node[i].c=c;i++;
      node[i].a=b;node[i].b=c;node[i].dp=node[i].c=a;i++;
      node[i].a=c;node[i].b=a;node[i].dp=node[i].c=b;i++;
      node[i].a=c;node[i].b=b;node[i].dp=node[i].c=a;
    }
    sort(node+1,node+6*n+1,cmp);
    int maxx=node[6*n].c;
    for(i=6*n-1;i>=1;i--)
    {
      for(j=i+1;j<=6*n;j++)
      {
        if(node[i].a<node[j].a&&node[i].b<node[j].b&&node[i].dp<node[i].c+node[j].dp)
          node[i].dp=node[i].c+node[j].dp;
      }
      if(node[i].dp>maxx) maxx=node[i].dp;
    }
    /*printf("ssssssssssssssssss\n");
    for(i=1;i<=6*n;i++)
    {
      printf("%d %d %d %d\n",node[i].a,node[i].b,node[i].c,node[i].dp);
    }*/

    printf("Case %d: maximum height = %d\n",cas++,maxx);
  }
  return 0;
}

  

时间: 2024-10-11 01:01:02

hdu 1069 Monkey and Banana (最长上升子序列)的相关文章

[2016-03-30][HDU][1069][Monkey and Banana]

时间:2016-03-27 15:19:40 星期日 题目编号:[2016-03-30][HDU][1069][Monkey and Banana] 题目大意:给定n种积木无限个,问这些积木最大能叠多高,上面的积木长宽必须严格小于下面的积木 分析: dp[i]表示第i个积木在顶部时候的最大高度,那么dp[i] = max(dp[i],dp[j] + h[i]);?ji能放在j上面?ji能放在j上面 初始条件就是长宽最大的高度是它自己, #include <algorithm> #include

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

Monkey and Banana Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever

HDU 1069 Monkey and Banana (动规)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7248    Accepted Submission(s): 3730 Problem Description A group of researchers are designing an experiment to test the IQ of a

HDU 1069 Monkey and Banana dp 题解

HDU 1069 Monkey and Banana 题解 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种长方体,计算,最高能堆多高.要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽. 输入输出 开始一个数n,表示有多少种木块,木块的数量无限,然后接下来的n行,每行3个数,是木块的长宽高三个参量 输出使用这些在满足条件的情况下能够摆放的最大高度 解

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

---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13003    Accepted Submission(s): 6843 Problem Description A group of researchers are designing an experiment to te

HDU 1069 Monkey and Banana 基础DP

题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. 简单的DP,依然有很多地发给当时没想到.比如优先级,比如这么简单粗暴的选择. 1 /* 2 大意是.给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 3 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. 4 5 样例: 6 10 20 30 7 10

hdu 1069 Monkey and Banana (结构体排序,也属于简单的dp)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7770    Accepted Submission(s): 4003 Problem Description A group of researchers are designing an experiment to test the IQ of a

HDU 1069 Monkey and Banana LCS变形

点击打开链接题目链接 Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7617    Accepted Submission(s): 3919 Problem Description A group of researchers are designing an experiment to test

DP [HDU 1069] Monkey and Banana

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7854    Accepted Submission(s): 4051 Problem Description A group of researchers are designing an experiment to test the IQ of a

hdu(1069)——Monkey and Banana(LIS变形)

题意: 现在给你n个石块,然后它由坐标来表示(x,y,z).但是它可以有不同的方法,也就是说它的三个坐标可以轮换着来的. 石块的数量不限,但是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所能拼成的最大高度是多少. 思路: 因为坐标有多种情况,所以我们可以把每次的情况都存下去. 这里需要注意的是,在保存的时候,我们要保持x的坐标是大于y的,这样方便我们之后的排序. 然后就直接求最长递减子序列就好了. #include<stdio.h> #include<string.h>