标签:nyoj16
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 <algorithm> using namespace std; struct Node{ int wide, len; } arr[1002]; int dp[1002]; //dp[i]存储以第i个矩形结尾能嵌套得到的数量 bool cmp(Node a, Node b){ if(a.len < b.len) return 1; else if(a.len == b.len) return a.wide < b.wide; return 0; } int main(){ int t, n; Node temp; scanf("%d", &t); while(t--){ scanf("%d", &n); for(int i = 0; i < n; ++i){ scanf("%d%d", &arr[i].wide, &arr[i].len); if(arr[i].wide > arr[i].len) swap(arr[i].wide, arr[i].len); dp[i] = 1; } sort(arr, arr + n, cmp); for(int i = 1; i < n; ++i){ for(int j = i - 1; j >= 0; --j){ if(arr[i].wide > arr[j].wide && arr[i].len > arr[j].len) dp[i] = max(dp[j] + 1, dp[i]); } } printf("%d\n", *max_element(dp, dp + n)); } return 0; }
NYOJ16 矩形嵌套 【DP】,布布扣,bubuko.com
标签:nyoj16
原文地址:http://blog.csdn.net/chang_mu/article/details/26010161