问题 A: 矩形嵌套
时间限制: 1 Sec 内存限制: 64 MB
献花: 20 解决: 17
[献花][花圈][TK题库]
题目描述
有n个矩形,每个矩形可以用a,b来描述,表示长和宽。矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
typedef struct Rectanle
{
int w;
int l;
}Rect;
using namespace std;
const int MaxN = 1010;
bool cmp(Rect a, Rect b)
{
return a.l < b.l;
}
int main()
{
#ifdef _DEBUG
freopen("data.txt", "r+", stdin);
#endif // _DEBUG
std::ios::sync_with_stdio(false);
Rect rect[MaxN];
int dp[MaxN];
int n, m;
cin >> n;
while (n--)
{
cin >> m; dp[0] = 1;
for (int i = 0; i < m; ++i)
{
int w, l;
cin >> l >> w;
if (l < w)
swap(l, w);
rect[i].l = l;
rect[i].w = w;
}
sort(rect, rect + m, cmp);
int res = 1;
for (int i = 1; i < m; ++i)
{
dp[i] = 1;
for (int k = 0; k < i; ++k)
{
if (rect[i].w > rect[k].w && rect[i].l > rect[k].l && dp[i] <= dp[k])
dp[i] = dp[k] + 1;
}
if (dp[i] > res)
res = dp[i];
}
cout << res << endl;
}
return 0;
}
/**************************************************************
Problem: 21773
User: Sharwen
Language: C++
Result: 升仙
Time:0 ms
Memory:1700 kb
****************************************************************/