#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int max_size = 1005;
int a, b;
int DP[max_size];
///定义结构体
typedef struct Arry
{
int lon; ///矩形的长
int wide; ///矩形的宽
}Arry;
Arry arry[max_size];
///用来初始化
void init(int t)
{
memset(DP, -1, sizeof(DP));
for(int i = 0; i < t; ++i)
{
scanf("%d %d", &a, &b);
if(a > b)
{
arry[i].lon = a;
arry[i].wide = b;
}
else
{
arry[i].lon = b;
arry[i].wide = a;
}
}
}
///起码结构体排序学会了
int cmp(const void *a, const void *b)
{
struct Arry *c = (Arry *)a;
struct Arry *d = (Arry *)b;
return c->lon - d->lon;
}
int main()
{
int n;
int t;
scanf("%d", &n);
while(n--)
{
scanf("%d", &t);
init(t);
qsort(arry, t, sizeof(arry[0]), cmp);
for(int i = 0; i < t; ++i)
{
DP[i] = 1; ///将每一个DP[i]值都初始化为1,起码自己算一个
for(int j = 0; j < i; ++j)
{
if(arry[i].lon > arry[j].lon && arry[i].wide > arry[j].wide) ///如果能嵌套
if(DP[i] < DP[j] + 1) ///如果目前DP[i]较小,将DP[i]更新
DP[i] = DP[j] + 1;
}
}
int maxnum = 0;
for(int i = 0; i < t; ++i)
{
if(maxnum < DP[i])///DP[]里最大的那个,就是能进行最多次的嵌套
maxnum = DP[i];
}
printf("%d\n", maxnum);
}
return 0;
}
DAG模型