标签:bool style field 转移 content sort rip 多少 数字
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #define ll long long 5 using namespace std; 6 const int N=100010,mo=1e9+7; 7 int n,c; 8 ll f[N],g[N],fac[2*N],ny[2*N],r; 9 struct edge { ll x,y; }a[N]; 10 ll ksm(ll a,ll b) { for (r=1;b;b>>=1,a=a*a%mo) if (b&1) r=r*a%mo; return r; } 11 ll C(int b,int a) 12 { 13 if (a==0||a==b) return 1; 14 return ((fac[b]*ny[a])%mo*ny[b-a])%mo; 15 } 16 bool cmp(edge a,edge b) { return a.x<b.x||a.x==b.x&&a.y<b.y; } 17 ll calc(int i,int j) 18 { 19 int x=a[j].x-a[i].x,y=a[j].y-a[i].y; 20 if (x<0||y<0) return 0; 21 if (a[j].y-1-a[i].x<0||a[j].x+1-a[i].y<0) return C(x+y,x); 22 return (C(x+y,x)-C(x+y,a[j].y-1-a[i].x)+mo)%mo; 23 } 24 int main() 25 { 26 scanf("%d%d",&n,&c); 27 for (int i=1;i<=c;i++) scanf("%d%d",&a[i].x,&a[i].y); 28 fac[1]=ny[1]=1; for (int i=2;i<=n*2;i++) fac[i]=(fac[i-1]*i)%mo,ny[i]=ksm(fac[i],mo-2); 29 a[c+1].x=n,a[c+1].y=n,sort(a,a+c+1,cmp); 30 for (int i=1;i<=c+1;i++) 31 { 32 for (int j=1;j<i;j++) (g[i]+=f[j]*calc(j,i)%mo)%=mo; 33 f[i]=(calc(0,i)-g[i]+mo)%mo; 34 } 35 printf("%lld",f[c+1]); 36 }
标签:bool style field 转移 content sort rip 多少 数字
原文地址:https://www.cnblogs.com/Comfortable/p/10331482.html