显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
#define Min(a,b) ((a)>(b)?(b):(a))
using namespace std;
int n;
struct dd{
int l,r;
}jie[5002];
bool comp(const dd & a,const dd & b){
return a.l<b.l;
}
int f[5002];
int main(){
freopen("google.in","r",stdin);
freopen("google.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;++i) {
scanf("%d%d",&jie[i].l,&jie[i].r);
}
sort(jie+1,jie+n+1,comp);
memset(f,25,sizeof(f));
f[0]=0;
for(int i=1;i<=n;++i)
for(int j=jie[i].l;j<=jie[i].r;++j)
f[j]=Min(f[j],f[jie[i].l-1]+1);
printf("%d",f[n]);
getchar();getchar();
}