HDU 1069 基础动态规划+排序

题意 给出n种立方体石头 当且仅当一块石头的底部宽度长度都小于一块石头的时候才能放在上面 问最高能放多高?石头不限数目

然而同样一种石头采用同样的摆放方式 两快相同石头一定无法进行放置 所以 一块石头的一种摆放方式最多使用一次

进行一下排序 让长与宽最小的放在最前面 然后就是可爱的dp模板了

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
struct node
{
    int a,b,c;
};
node q[50000];
int dp[50000];
int cmp(node z,node x)
{
    if(z.b==x.b)
        return z.a>x.a;
    else return z.b>x.b;
}
int main(){
int n;
int tt=1;
while(~scanf("%d",&n))
{
    if(n==0)
        break;
    int w=0;
    for(int i=0;i<n;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        q[w].a=x;
        q[w].b=y;
        q[w++].c=z;
        q[w].a=y;
        q[w].b=x;
        q[w++].c=z;
        q[w].a=y;
        q[w].b=z;
        q[w++].c=x;
        q[w].a=z;
        q[w].b=y;
        q[w++].c=x;
        q[w].a=x;
        q[w].b=z;
        q[w++].c=y;
        q[w].a=z;
        q[w].b=x;
        q[w++].c=y;
    }
    sort(q,q+w,cmp);
    dp[0]=q[0].c;
    for(int i=1;i<w;i++)
    {
        int minn=0;
        for(int k=0;k<i;k++)
        {
            if(q[k].a>q[i].a&&q[k].b>q[i].b)
            {
                if(dp[k]>minn)
                {
                    minn=dp[k];
                }
            }
        }
        dp[i]=q[i].c+minn;
    }
    int ans=0;
    for(int i=0;i<w;i++)
    {
        if(dp[i]>ans)
        {
            ans=dp[i];
        }
    }
    printf("Case %d: maximum height = %d\n",tt++,ans);
}
}

  

时间: 2024-10-16 13:41:18

HDU 1069 基础动态规划+排序的相关文章

C - Monkey and Banana HDU 1069( 动态规划+叠放长方体)

C - Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1069 Description A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof

HDU 1069 Monkey and Banana dp 题解

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

HDU 1069&amp;&amp;HDU 1087 (DP 最长序列之和)

H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1087 Appoint description:  System Crawler  (2015-11-18) Description Nowadays, a kind of chess game called “Su

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

[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(二维偏序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 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 2000 ASCII码排序

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2000 题目大意:按各字符的ASCII码从小到大的顺序进行排序 注意格式哦!输出时字符中间用一个空格分开 1 #include<stdio.h> 2 int main() 3 { 4 char a,b,c,t; 5 while(scanf("%c%c%c",&a,&b,&c)!=EOF) 6 { 7 getchar(); 8 if(a>b) 9 {

hdu 2647 Reward (拓扑排序分层)

Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3815    Accepted Submission(s): 1162 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wa