这名字很赛艇啊
其实不是很懂做法
http://blog.163.com/ele_ele/blog/static/2571160702016419115317400/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x){
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
const int N=505;
const int P=1000000007;
int n,a[N],b[N];
int sum[N],f[N<<1][N];
int inv[N],C[N<<1][N];
int sx[N<<1],m;
ll ans;
int main()
{
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
read(n);
for (int i=1;i<=n;i++)
read(a[i]),read(b[i]),sx[++m]=a[i],sx[++m]=b[i]+1;
sort(sx+1,sx+m+1);
m=unique(sx+1,sx+m+1)-sx-1;
inv[1]=1;
for (int i=2;i<=n;i++) inv[i]=(ll)(P-P/i)*inv[P%i]%P;
for (int i=1;i<m;i++){
C[i][0]=1;
for (int j=1;j<=n;j++)
C[i][j]=(ll)C[i][j-1]*(sx[i+1]-sx[i]+j-1)%P*inv[j]%P;
}
for (int i=1;i<m;i++)
{
f[i-1][0]=1;
for (int j=1;j<=n;j++)
{
sum[j]=sum[j-1];
f[i][j]=f[i-1][j];
if (a[j]<=sx[i] && sx[i+1]-1<=b[j])
{
sum[j]++;
for (int k=0;k<j;k++){
f[i][j]+=(ll)f[i-1][k]*C[i][sum[j]-sum[k]]%P;
if (f[i][j]>=P) f[i][j]-=P;
}
}
}
}
for (int i=1;i<=n;i++)
ans=ans+f[m-1][i];
printf("%lld\n",ans%P);
return 0;
}