题目链接:poj1065
/*
题意:有一些木棒,它们的长度(l)和质量(w)都已经知道,需要一个机器处理这些木棒,
机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于
第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间
思路:首先对长度和质量从大到小排序,然后找质量的单调最长子序列长度,类似hdu1257最少拦截系统
*/
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 5005;
int d[N];
struct node
{
int l,w;
bool operator < (const node &cmp) const{
return l > cmp.l || l == cmp.l && w > cmp.w;//从大到小排序
}
}s[N];
int main()
{
int T,n,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i = 0; i < n; i ++)
scanf("%d%d",&s[i].l,&s[i].w);
sort(s,s+n);
int top = 0;
d[0] = -inf;
for(i = 0; i < n; i ++){
if(s[i].w > d[top]){
d[++top] = s[i].w;
continue;
}
int pos = lower_bound(d, d+top+1, s[i].w) - d;
d[pos] = s[i].w;
}
printf("%d\n",top);
}
return 0;
}