类似于dp的思想
1 10 20 30 2 6 8 10 5 5 5 7 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 5 31 41 59 26 53 58 97 93 23 84 62 64 33 83 27 0
Case 1: maximum height = 40 Case 2: maximum height = 21 Case 3: maximum height = 28 Case 4: maximum height = 342
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <deque>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define MAXN 200 + 10
struct node{
int x,y,z;
}a[MAXN];
int dp[MAXN];
bool cmp(node a,node b){
if(a.x == b.x){
return a.y < b.y;
}
return a.x < b.x;
}
int main(){
int n,i,con,aa,bb,cc,j;
int cas = 1;
while(cin>>n){
if(n == 0){
break;
}
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++){
scanf("%d%d%d",&aa,&bb,&cc);
a[i*6].x=aa,a[i*6].y=bb,a[i*6].z=cc;
a[i*6+1].x=aa,a[i*6+1].y=cc,a[i*6+1].z=bb;
a[i*6+2].x=bb,a[i*6+2].y=aa,a[i*6+2].z=cc;
a[i*6+3].x=bb,a[i*6+3].y=cc,a[i*6+3].z=aa;
a[i*6+4].x=cc,a[i*6+4].y=aa,a[i*6+4].z=bb;
a[i*6+5].x=cc,a[i*6+5].y=bb,a[i*6+5].z=aa;
}
sort(a,a+n*6,cmp);//按照长宽从小到大的顺序排
int ans=0;
int tmp;
for(i=0;i<6*n;i++){
tmp = 0;
for(j=0;j<i;j++){
if(a[i].x>a[j].x && a[i].y>a[j].y){
tmp = max(tmp,a[j].z);
}
}
a[i].z+=tmp;
ans = max(ans,a[i].z);
}
printf("Case %d: maximum height = %d\n",cas,ans);
cas++;
}
return 0;
}
原文地址:http://blog.csdn.net/zcr_7/article/details/41214637