给出若干个 木棍
每个木棍有l w两个属性
问最少需要几个木棍序列 使得木棍的l w都是不减的
贪心:如果a1后面可以放a2那么 a1--》a2一条边[topo图既是感],因为每个点都要经过,所以怎么走都一样
于是贪心直接构造合法的序列就好,序列个数一定最优= =
STL dafa good
#include <bits/stdc++.h>
#define L first
#define W second
using namespace std;
typedef pair<int,int> pii;
pii a[6000];
bool used[6000];
int n;
void Gao()
{
memset(used,0,sizeof(used));
cin>>n;
for (int i=0;i<n;i++)
{
int l,w;
scanf("%d%d",&l,&w);
a[i]=make_pair(l,w);
}
sort(a,a+n);
int ans=0;
for (int i=0;i<n;i++)
{
int teml,temw;
if (used[i])
continue;
used[i]=true;
ans++;
teml=a[i].L;temw=a[i].W;
for (int j=i+1;j<n;j++)
{
if (used[j])
continue;
if (teml<=a[j].L && temw<=a[j].W)
{
teml=a[j].L;temw=a[j].W;
used[j]=true;
}
}
}
cout<<ans<<endl;
}
int main()
{
//freopen("a.in","r",stdin);
int T;
cin>>T;
while (T--)
Gao();
return 0;
}