1 10 1 2 2 4 5 8 6 10 7 9 3 1 5 8 12 10 9 7 2 2
5
#include "stdio.h" #include "string.h" #define N 1000+10 int a[N][2]; int b[N]; int main() { int n,m,result; int i,j,temp,temp1,max; scanf("%d",&n); while(n--) { scanf("%d",&m); for(i=1;i<=m;i++) //读入测试数据 { scanf("%d%d",&temp,&temp1); a[i][0]=temp<temp1?temp:temp1; //矩形的宽 a[i][1]=temp<temp1?temp1:temp; //矩形的长 } for(i=1;i<=m;i++) //对矩形的宽进行由小到大排序 for(j=i+1;j<=m;j++) if(a[i][0]>a[j][0]) {temp=a[i][0];a[i][0]=a[j][0];a[j][0]=temp; temp1=a[i][1];a[i][1]=a[j][1];a[j][1]=temp1;} //求长进行最长升序列求解 memset(b,0,sizeof(b)); result=0; for(i=m;i>0;i--) { max=0; for(j=i+1;j<=m;j++) if(a[j][1]>a[i][1] && a[j][0]>a[i][0]) max=max>b[j]?max:b[j]; b[i]=max+1; result=result>b[i]?result:b[i]; } printf("%d\n",result); } return 0; }
原文:http://blog.csdn.net/user_longling/article/details/21978333