hdu 1069 Monkey and Banana

http://acm.hdu.edu.cn/showproblem.php?pid=1069

hdu 1069 Monkey and Banana
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define maxn 1000
 5 using namespace std;
 6 
 7 struct node
 8 {
 9     int x,y,z;
10     bool operator <(const node &a)const
11     {
12         return (x<a.x)||(x==a.x&&y<a.y);
13     }
14 }p[maxn];
15 int n,x,y,z;
16 int dp[maxn];
17 int main()
18 {
19     int t=0;
20     while(scanf("%d",&n)&&n)
21     {
22         int num=0;
23         for(int i=0; i<n; i++)
24         {
25             scanf("%d%d%d",&x,&y,&z);
26             p[num].x=x;p[num+1].x=x;p[num+2].y=x;p[num+3].z=x;p[num+4].y=x;p[num+5].z=x;
27             p[num].y=y;p[num+1].z=y;p[num+2].x=y;p[num+3].x=y;p[num+4].z=y;p[num+5].y=y;
28             p[num].z=z;p[num+1].y=z;p[num+2].z=z;p[num+3].y=z;p[num+4].x=z;p[num+5].x=z;
29             num+=6;
30         }
31         sort(p,p+num);
32         int max1=0;
33         memset(dp,0,sizeof(dp));
34         dp[0]=p[0].z;
35         for(int i=1; i<num; i++)
36         {
37             int min1=0;
38             for(int j=i-1; j>=0; j--)
39             {
40                 if(p[i].y>p[j].y&&dp[j]>min1&&p[i].x>p[j].x)
41                 {
42                     min1=dp[j];
43                 }
44             }
45             dp[i]=min1+p[i].z;
46             if(dp[i]>max1)
47             {
48                 max1=dp[i];
49             }
50         }
51         t++;
52         printf("Case %d: maximum height = %d\n",t,max1);
53     }
54     return 0;
55 }
View Code

hdu 1069 Monkey and Banana

上一篇:OpenCascade Tcl vs. ACIS Scheme


下一篇:codeforces C. Arithmetic Progression 解题报告