dp、贪心均能解,我用的是贪心。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 210
using namespace std;
typedef struct {
int x,y;
}Node;
Node T[N];
bool vis[N];
bool cmp(Node a,Node b)
{
return a.x < b.x;
}
int main()
{
int n;
cin >> n;
while(n--)
{
memset(vis,true,sizeof(vis));
int m;
cin >> m;
int a,b;
for(int e=1; e<=m; ++e)
{cin >> a >>b;
T[e].x = a>b?b:a;
T[e].y = a>b?a:b;
}
sort(T+1, T+m+1, cmp);
int g = 0,ma,i;
while(1)
{
ma = 0;
for(i=1; i<=m; ++i)
if(vis[i] == true)
break;
vis[i] = false;
if(i==m+1)
break;
ma = (T[i].y+1)/2;
++g;
for(i+=1;i<=m; ++i)
if(vis[i]&&(T[i].x+1)/2 > ma)
{
vis[i] = false;
ma = (T[i].y+1)/2;
}
}
cout << g*10<<endl;
}
return 0;
}