​Monkey and Banana HDU - 1069​​​
有偷偷的看了一下题解,然后理解了。自己敲了一遍没有任何问题。
题意
一个团队研究猴子的智商,他们在房屋顶放了一个香蕉,与此同时,给猴子提供了一些盒子。如果猴子足够聪明,他们就可以通过摆盒子建造一个路到达房顶拿到食物。研究室由n个类型的盒子,每个类型的盒子数量不限。每个类型的盒子会给出长宽高。盒子可以调整。他们想要确保搭积木的最高的那个到达屋顶。积木只能被房子另一个积木的顶部。只要上面的基础维度都严格小于小面那个积木的(一样大是不可以的因为猴子要落脚)–注意要求是必须长宽都小。
输入:n和n种不同的的x,y,z。
输出:能到达的最大高度。
思路:首先将输入的x,y,z,可能的基础维度放入数组中,对其按照x,y的大小从小到达排序。最后进行dp操作。这里时从小到大的开始dp,这里可以保证,每次dp的值都是对这个积木来说最大的高度。board[i].dp=max(board[j].dp+board[i].high,board[i].dp)。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=200;
struct Block{
int x,y,high;
int dp;//该箱子在最下面时的最大高度
bool operator <(const Block &u)const{
if(x<u.x) return 1;
else if(x==u.x&&y<u.y) return 1;
else return 0;
}
}block[maxn];
int main()
{
int n;
int cnt=1;
int a,b,c,k;
while(~scanf("%d",&n)!=EOF&&n)
{
k=0;
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
if(a==b&&b==c)
{
block[k].x=a,block[k].y=b,block[k].high=c;block[k].dp=block[k].high;k++;
}
else if(a==b&&a!=c)
{
block[k].x=a,block[k].y=b,block[k].high=c;block[k].dp=block[k].high;k++;
block[k].x=a,block[k].y=c,block[k].high=b;block[k].dp=block[k].high;k++;
block[k].x=c,block[k].y=a,block[k].high=b;block[k].dp=block[k].high;k++;
}
else if(a==c&&a!=b)
{
block[k].x=a,block[k].y=c,block[k].high=b;block[k].dp=block[k].high;k++;
block[k].x=a,block[k].y=b,block[k].high=c;block[k].dp=block[k].high;k++;
block[k].x=b,block[k].y=a,block[k].high=c;block[k].dp=block[k].high;k++;
}
else if(b==c&&b!=a)
{
block[k].x=b,block[k].y=c,block[k].high=a;block[k].dp=block[k].high;k++;
block[k].x=b,block[k].y=a,block[k].high=c;block[k].dp=block[k].high;k++;
block[k].x=a,block[k].y=b,block[k].high=c;block[k].dp=block[k].high;k++;
}
else
{
block[k].x=a,block[k].y=b,block[k].high=c;block[k].dp=block[k].high;k++;
block[k].x=a,block[k].y=c,block[k].high=b;block[k].dp=block[k].high;k++;
block[k].x=b,block[k].y=a,block[k].high=c;block[k].dp=block[k].high;k++;
block[k].x=b,block[k].y=c,block[k].high=a;block[k].dp=block[k].high;k++;
block[k].x=c,block[k].y=a,block[k].high=b;block[k].dp=block[k].high;k++;
block[k].x=c,block[k].y=b,block[k].high=a;block[k].dp=block[k].high;k++;
}
}
sort(block,block+k);
int ans=-1;
//每个block[i]为当前最底层
for(int i=1;i<k;i++)
{
for(int j=0;j<i;j++)
{
if(block[i].x>block[j].x&&block[i].y>block[j].y)
block[i].dp=max(block[j].dp+block[i].high,block[i].dp);
}
if(block[i].dp>ans)
ans=block[i].dp;
}
printf("Case %d: maximum height = %d\n",cnt++,ans);
}
return 0;