您的位置:首页 > 其它

HDU-1069-DP-Monkey and Banana

2015-10-30 01:52 411 查看
题意

无限提供N种箱子 求这些箱子能累的最高高度且下面箱子要比上面箱子长宽都大

思路

现将箱子按长或宽排序 再对高进行 DP

DP[i] = max (DP[i],DP[j]+h[i])

[code]#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 330
typedef struct node
{
    int x,y,h,are;
}inode;
inode Node
;
int cnt=1;
int dp
;
bool comp(inode a,inode b)
{
    return a.are<b.are;

}

int main(void)
{
    int n;
    int len;
    int x,y,h;
    while(~scanf("%d",&n)>>n&&n)
    {
        len = 0;
        while(n--)
        {
            scanf("%d%d%d",&x,&y,&h);

                Node[len].x = x;
                Node[len].y = y;
                Node[len].h = h;
                Node[len].are = x*y;
                len++;
                Node[len].x = y;
                Node[len].y = h;
                Node[len].h = x;
                Node[len].are = y*h;
                len++;
                Node[len].x = x;
                Node[len].y = h;
                Node[len].h = y;
                Node[len].are = x*h;
                len++;

        }
        sort(Node,Node+len,comp);
        int MAX = 0;

        for(int i = 0;i < len; i++)
        {

            dp[i]=Node[i].h;
            for(int j = 0; j <  i; j++)
            if((Node[j].x < Node[i].x&&Node[j].y < Node[i].y)||(Node[j].y < Node[i].x&&Node[j].x < Node[i].y))
             {
                 dp[i]=max(dp[i],dp[j]+Node[i].h);

             }
            MAX = max(dp[i],MAX);
        }
        printf("Case %d: maximum height = %d\n",cnt++,MAX);
    }

    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: