1 条题解
-
0
C++ :
#include<cstdio> #define LL long long LL n,m,t,p; LL x[202],y[202]; namespace A { LL f[200001]; LL ans[202]; LL power(LL x,LL n) { LL t; if (n==0) return 1; t=power(x,n/2); if (n%2==0) return (t*t)%p; else return (((t*t)%p)*x)%p; } LL count(LL x,LL y) { return (f[x+y]*power((f[x]*f[y])%p,p-2))%p; } void solve() { int i,j; f[0]=1; for (i=1;i<=n+m;i++) f[i]=(f[i-1]*i)%p; for (i=1;i<=t;i++) { ans[i]=count(x[i],y[i]); for (j=1;j<=i-1;j++) if (y[j]<=y[i]) ans[i]=(ans[i]+p-(ans[j]*count(x[i]-x[j],y[i]-y[j])%p))%p; } printf("%lld\n",ans[t]); } } namespace B { const LL pp[4]={3,5,6793,10007}; LL fac[4][10007]; LL ans[202]; LL power(LL a,LL b,LL p) { LL c; if (b==0) return 1; c=power(a,b/2,p); if (b%2==0) return (c*c)%p; else return (((c*c)%p)*a)%p; } LL f1(LL x,LL p) { LL pp,ans; pp=p; ans=0; while (x/pp>0) { ans+=x/pp; pp*=p; } return ans; } LL f2(LL x,int i) { LL ans; ans=1; while (x>0) { if ((x/pp[i])%2==1) ans=(ans*(-fac[i][x%pp[i]]+pp[i])%pp[i])%pp[i]; else ans=(ans*fac[i][x%pp[i]])%pp[i]; x/=pp[i]; } return ans; } LL count(LL x,LL y) { LL dx,ex; int i; ex=0; for (i=0;i<=3;i++) { if (f1(x+y,pp[i])-f1(x,pp[i])-f1(y,pp[i])>0) dx=0; else dx=(f2(x+y,i)*power((f2(x,i)*f2(y,i))%pp[i],pp[i]-2,pp[i]))%pp[i]; ex=(ex+(((p/pp[i]*dx)%p)*power(p/pp[i],pp[i]-2,pp[i]))%p)%p; } return ex; } void solve() { int i,j; for (i=0;i<=3;i++) { fac[i][0]=1; for (j=1;j<=pp[i]-1;j++) fac[i][j]=(fac[i][j-1]*j)%pp[i]; } for (i=1;i<=t;i++) { ans[i]=count(x[i],y[i]); for (j=1;j<=i-1;j++) if (y[j]<=y[i]) ans[i]=(ans[i]+p-(ans[j]*count(x[i]-x[j],y[i]-y[j])%p))%p; } printf("%lld\n",ans[t]); } } int main() { LL i,j,temp; // freopen("path.in","r",stdin); // freopen("path.out","w",stdout); scanf("%lld%lld%lld%lld",&n,&m,&t,&p); for (i=1;i<=t;i++) scanf("%d%d",&x[i],&y[i]); t++; x[t]=n; y[t]=m; for (i=1;i<=t-1;i++) for (j=i+1;j<=t;j++) if ((x[i]>x[j])||((x[i]==x[j])&&(y[i]>y[j]))) { temp=x[i]; x[i]=x[j]; x[j]=temp; temp=y[i]; y[i]=y[j]; y[j]=temp; } if (p==1000003) A::solve(); else B::solve(); return 0; }
- 1
信息
- ID
- 954
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者