http://acm.hdu.edu.cn/showproblem.php?pid=1069
类似于最长下降子序列
我的代码
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 const int N=100;
5 struct block
6 {
7 int x,y,z;
8 }a[N];
9 int f[N];
10 int cmp(const void *a,const void *b)
11 {
12 return ((block*)b)->x - ((block*)a)->x;
13 }
14 int main()
15 {
16 int n,m,c=0;
17 while (scanf("%d",&n) && n)
18 {
19 m=0;
20 int xx,yy,zz,t,i,j;
21 a[0].x=a[0].y=2000000000;
22 for (i=1;i<=n;i++)
23 {
24 scanf("%d%d%d",&xx,&yy,&zz);
25 a[++m].z=zz; a[m].x=xx>yy?xx:yy; a[m].y=xx<yy?xx:yy;
26 t=xx; xx=yy; yy=zz; zz=t;
27 a[++m].z=zz; a[m].x=xx>yy?xx:yy; a[m].y=xx<yy?xx:yy;
28 t=xx; xx=yy; yy=zz; zz=t;
29 a[++m].z=zz; a[m].x=xx>yy?xx:yy; a[m].y=xx<yy?xx:yy;
30 }
31 qsort(a+1,m,sizeof(a[0]),cmp);
32 memset(f,0,sizeof(f));
33 for (i=1;i<=m;i++)
34 {
35 t=0;
36 for (j=1;j<i;j++)
37 if (a[i].x<a[j].x && a[i].y<a[j].y)
38 t>?=f[j];
39 f[i]=t+a[i].z;
40 }
41 int ans=0;
42 for (i=1;i<=m;i++) ans>?=f[i];
43 printf("Case %d: maximum height = %d\n",++c,ans);
44 }
45 }