1 10 1 2 2 4 5 8 6 10 7 9 3 1 5 8 12 10 9 7 2 2
5
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int dp[1100]; struct rectangle { int a,b; }REC[1100]; bool cmp(rectangle x,rectangle y)//对长进行排序,求宽的最大上升子序列 { if(x.a==y.a) return x.b<y.b; else return x.a<y.a; } int max(int a,int b) { if(a>b) return a; else return b; } int main() { int T,n,x,y,i,j; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",&x,&y); REC[i].a=max(x,y); REC[i].b=x+y-max(x,y); } sort(REC,REC+n,cmp); dp[0]=1; int ans=0; for(i=1;i<=n;i++) { for(j=0;j<i;j++) { if(REC[i].a!=REC[j].a && REC[i].b>REC[j].b && dp[j]>ans) ans=dp[j]; } dp[i]=ans+1; ans=0; } for(i=0;i<=n;i++) { if(dp[i]>ans) ans=dp[i]; } printf("%d\n",ans); } return 0; }
原文:http://blog.csdn.net/holyang_1013197377/article/details/40660081