hdu 1069

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069

其实,说白了,就是求最长单调子序列。。。

思路:先排序之后,直接用经典的求最长单调子序列的方法求即可;

View Code
 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 struct Node{
 5     int l,w,h;
 6 }node[1000];
 7 int dp[1000];
 8 
 9 int cmp(const Node &a,const Node &b){
10     if(a.l>b.l)return 1;
11     if(a.l==b.l&&a.w>b.w)return 1;
12     return 0;
13 }
14 
15 int main(){
16     int n,x,y,z,_case=1;
17     while(scanf("%d",&n)!=EOF){
18         if(n==0)break;
19         int count=0;
20         for(int i=0;i<n;i++){
21             scanf("%d%d%d",&x,&y,&z);
22             node[count].l=x,node[count].w=y,node[count++].h=z;
23             node[count].l=x,node[count].w=z,node[count++].h=y;
24             node[count].l=y,node[count].w=x,node[count++].h=z;
25             node[count].l=y,node[count].w=z,node[count++].h=x;
26             node[count].l=z,node[count].w=x,node[count++].h=y;
27             node[count].l=z,node[count].w=y,node[count++].h=x;
28         }
29         sort(node,node+count,cmp);
30         memset(dp,0,sizeof(dp));
31         for(int i=0;i<count;i++){
32             dp[i]=node[i].h;
33             for(int j=0;j<=i;j++){
34                 //符合条件的
35                 if(node[i].l<node[j].l&&node[i].w<node[j].w){
36                     dp[i]=max(dp[i],dp[j]+node[i].h);
37                 }
38             }
39         }
40         int ans=0;
41         for(int i=0;i<count;i++){
42             ans=max(ans,dp[i]);
43         }
44         printf("Case %d: maximum height = %d\n",_case++,ans);
45     }
46     return 0;
47 }
原文地址:https://www.cnblogs.com/wally/p/2954208.html