直接贪心模拟就OK~~
</pre><pre code_snippet_id="415167" snippet_file_name="blog_20140703_4_669883" name="code" class="cpp">
</pre><pre code_snippet_id="415167" snippet_file_name="blog_20140703_5_6559227" name="code" class="cpp">#include <map>
#include <set>
#include <list>
#include <cmath>
#include<cctype>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b)
{
return a % b == 0 ? b : gcd(b, a % b);
}
#define MAXN 5005
struct node
{
int l,r;
friend bool operator < (const node &a,const node &b)
{
if (a.l==b.l) return a.r<b.r;
return a.l<b.l;
}
}src[MAXN];
bool vis[MAXN];
int ans,n;
void slove()
{
sort(src,src+n);
memset(vis,false,sizeof(vis));
ans=0;
//for (int i=0;i<n;i++)
// printf("%d %d\n",src[i].l,src[i].r);
for (int i=0;i<n;i++)
{
if (vis[i]) continue;
ans++;
vis[i]=true;
int tmp=src[i].r;
for (int j=i;j<n;j++)
if (src[j].r>=tmp && !vis[j]) {vis[j]=true;tmp=src[j].r;}
}
printf("%d\n",ans);
}
int main()
{
//freopen("sample.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (int i=0;i<n;i++)
scanf("%d%d",&src[i].l,&src[i].r);
slove();
}
return 0;
}