#HDU 1069 简单dp

Monkey and Banana

题意: 给定一些长方体,问可以摆出的最大高度,要求下层长宽必须严格大于上层。

分析: 每个长方体都有三种摆放的顺序呢,那么接下来就把所有情况记录下来搭建积木。

代码如下:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cctype>
#define INF 0x3f3f3f3f 
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

struct node{
    int a,b,h;
    bool operator <(const node s)const{
        if(a == s.a)
            return b < s.b;
        else return a < s.a;
    }
}box[100];
int dp[100];

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n,kase = 1;
    while(cin>> n && n){
        int s[3],k = 0;
        for(int i=0;i<n;i++){
            cin>> s[0] >> s[1] >> s[2];
            sort(s,s+3);
            //转换成三个不同高度的长方体
            box[k].a = s[0],box[k].b = s[1],box[k].h = s[2];k++;
            box[k].a = s[0],box[k].b = s[2],box[k].h = s[1];k++;
            box[k].a = s[1],box[k].b = s[2],box[k].h = s[0];k++;
        }

        sort(box,box+k);

        /*for(int i=0;i<k;i++)
            cout<< box[i].a <<box[i].b << box[i].h<<endl;
        */
        for(int i=0;i<k;i++)
            dp[i] = box[i].h;
        for(int i=0;i<k;i++){
            for(int j=i+1;j>=0;j--){
                if(box[i].a>box[j].a && box[i].b>box[j].b){
                    if(dp[i]<dp[j] + box[i].h)
                        dp[i] = dp[j] + box[i].h;
                }
            }
        }

        int ans = dp[0];
        for(int i=0;i<k;i++){
            if(ans<dp[i])
                ans = dp[i];
        }
        printf("Case %d: maximum height = %d\n",kase++,ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值