标签:href 矩形 测试数据 class color 表示 nyoj logs net
http://acm.nyist.net/JudgeOnline/problem.php?pid=16
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<algorithm> 3 using namespace std; 4 5 const int maxn = 1000+5; 6 7 int n; 8 int dp[maxn]; 9 10 struct node 11 { 12 int a, b; 13 }a[maxn]; 14 15 bool cmp(node x, node y) 16 { 17 if (x.a == y.a) return x.b < y.b; 18 return x.a < y.a; 19 } 20 21 int main() 22 { 23 //freopen("D:\\txt.txt", "r", stdin); 24 int t; 25 cin >> t; 26 while (t--) 27 { 28 cin >> n; 29 for (int i = 0; i < n; i++) 30 { 31 cin >> a[i].a >> a[i].b; 32 if (a[i].a < a[i].b) 33 { 34 int temp = a[i].b; 35 a[i].b = a[i].a; 36 a[i].a = temp; 37 } 38 } 39 sort(a, a + n, cmp); 40 int _Max = 0; 41 for (int i = 0; i < n; i++) 42 { 43 dp[i] = 1; 44 for (int j = 0; j < i; j++) 45 { 46 if (a[j].a < a[i].a && a[j].b < a[i].b) 47 { 48 dp[i] = max(dp[i], dp[j] + 1); 49 } 50 } 51 if (dp[i]>_Max) _Max = dp[i]; 52 } 53 cout << _Max << endl; 54 } 55 return 0; 56 }
标签:href 矩形 测试数据 class color 表示 nyoj logs net
原文地址:http://www.cnblogs.com/zyb993963526/p/6358152.html