其他分享
首页 > 其他分享> > Monkey and Banana HDU - 1069 有点像背包,又像最长上升序列

Monkey and Banana HDU - 1069 有点像背包,又像最长上升序列

作者:互联网

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
struct node{
    int l,s,h;
};
vector<node>v;
//按照长宽排序 
bool cmp(node a,node b)
{
    if(a.l==b.l)
        return a.s<b.s;
    return a.l<b.l;
}
int dp[200];
int main()
{
    int n,kase;
    kase=0;
    while(cin>>n&&n)
    {
        int a,b,c;
        kase++;
        v.clear();
        memset(dp,0,sizeof dp);
        for(int i=1;i<=n;i++)
        {
            cin>>a>>b>>c;
            v.push_back({a,b,c});
            v.push_back({a,c,b});
            v.push_back({b,a,c});
            v.push_back({b,c,a});
            v.push_back({c,a,b});
            v.push_back({c,b,a});
        }
        sort(v.begin(),v.end(),cmp);
        int cmax=-INF;
        for(int i=0;i<v.size();i++)
        {
            //以哪一块为底部 
            dp[i]=v[i].h;
            for(int j=i-1;j>=0;j--)
                if(v[j].l<v[i].l&&v[j].s<v[i].s)
                    dp[i]=max(dp[i],dp[j]+v[i].h);
            cmax=max(cmax,dp[i]);
        }
        cout<<"Case "<<kase<<": maximum height = "<<cmax<<endl;
    }
    return 0;
}

 

标签:1069,node,HDU,Monkey,int,back,push,include,dp
来源: https://www.cnblogs.com/QingyuYYYYY/p/12238072.html