标签:style blog http color strong os
1 10 1 2 2 4 5 8 6 10 7 9 3 1 5 8 12 10 9 7 2 2
5
解题:排序,dp。。。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long 10 using namespace std; 11 struct rectangle { 12 int x,y; 13 } R[1010]; 14 int dp[1010]; 15 bool cmp(const rectangle &a,const rectangle &b) { 16 if(a.x < b.x || a.x == b.x && a.y <= b.y) return true; 17 return false; 18 } 19 int main() { 20 int ks,n,i,j,mx,ans; 21 scanf("%d",&ks); 22 while(ks--) { 23 scanf("%d",&n); 24 for(i = 0; i < n; i++) { 25 scanf("%d %d",&R[i].x,&R[i].y); 26 if(R[i].x > R[i].y) swap(R[i].x,R[i].y); 27 } 28 sort(R,R+n,cmp); 29 memset(dp,0,sizeof(dp)); 30 ans = dp[0] = 1; 31 for(i = 1; i < n; i++) { 32 for(mx = j = 0; j < i; j++) 33 if(R[j].x < R[i].x && R[j].y < R[i].y && mx < dp[j]) mx = dp[j]; 34 dp[i] = mx+1; 35 if(dp[i] > ans) ans = dp[i]; 36 } 37 printf("%d\n",ans); 38 } 39 return 0; 40 }
标签:style blog http color strong os
原文地址:http://www.cnblogs.com/crackpotisback/p/3840993.html