后面dp还简单的。。一开始不知道用排序,导致用二维数组在做。。没出来。。
排序后一下子简单了。。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 10010
using namespace std;
struct sb
{
int x;
int y;
int z;
bool operator < (const sb&wakaka)const
{
if(x==wakaka.x)
return y>wakaka.y;
return x>wakaka.x;
}
}square[maxn];
int dp[maxn];
int main()
{
int n;
int cin=0;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
else
cin++;
int t=1;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&square[t].x,&square[t].y,&square[t].z);
t++;
square[t].x=square[t-1].y;
square[t].y=square[t-1].x;
square[t].z=square[t-1].z;
t++;
square[t].x=square[t-2].z;
square[t].y=square[t-2].y;
square[t].z=square[t-2].x;
t++;
square[t].x=square[t-3].x;
square[t].y=square[t-3].z;
square[t].z=square[t-3].y;
t++;
square[t].x=square[t-4].y;
square[t].y=square[t-4].z;
square[t].z=square[t-4].x;
t++;
square[t].x=square[t-5].z;
square[t].y=square[t-5].x;
square[t].z=square[t-5].y;
t++;
}
sort(square+1,square+t+1);
int max1=0;
for(int i=t-1;i>=1;i--)
{
dp[i]=square[i].z;
for(int j=t-1;j>=i+1;j--)
if(square[i].x>square[j].x&&square[i].y>square[j].y)
dp[i]=max(dp[j]+square[i].z,dp[i]);
if(dp[i]>max1)
max1=dp[i];
}
printf("Case %d: maximum height = %d\n",cin,max1);
}
return 0;
}