NYOJ_232_How to eat more Banana

有限制条件的DP:

首先其实能堆叠起来,下面砖头的长和宽比上面的严格要大。

#include
#include
#include
#include
#include
#include<string>
using namespace std;
struct point 
{
    int x,y,z;
}p[1005];
bool cmp(point a,point b)
{
    if(a.x==b.x)
        return a.y>b.y;
    return a.x>b.x;
}
int dp[1005];
int main()
{
 int n,i,j,k=1,a,b,re,c;
 while(~scanf("%d",&n)&&n)
 {
     re=0;
     for(i=0;ii)
     {
         scanf("%d%d%d",&a,&b,&c);
         /*
         三种长宽高就够了,因为只要保证,x恒大于y
         */
         p[re].x=a>b?a:b;
         p[re].y=a<=b?a:b;
         p[re++].z=c;
         p[re].x=a>c?a:c;
         p[re].y=a<=c?a:c;
         p[re++].z=b;
         p[re].x=c>b?c:b;
         p[re].y=c<=b?c:b;
         p[re++].z=a;
     }
     sort(p,p+re,cmp);
     for(i=0;ii)
         dp[i]=p[i].z;
     int Max=0,all=0;
     for(i=0;ii)
     {    
         for(j=0,Max=0;jj)
        {
            if(p[i].xdp[j])  
                Max=dp[j];
        }
         if(dp[i]+Max>dp[i]) dp[i]+=Max; //dp[i]表示取第i个元素的能堆叠起来的最大高度为多少
         if(dp[i]>all) all=dp[i];
      }
     printf("Case %d: maximum height = %d\n",k++,all);
 }     
 return 0;
}

 

转载于:https://www.cnblogs.com/A-way/archive/2013/05/13/3075204.html

你可能感兴趣的:(NYOJ_232_How to eat more Banana)