标签:turn frame pid swa ref can init tom class
题目链接:
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod=110119; const int maxn=110; LL n,m,x[maxn],y[maxn],dp[maxn],p[110130]; int r; inline void init() { p[0]=1; for(int i=1;i<=110119;i++)p[i]=p[i-1]*(LL)i%mod; } LL pow_mod(LL a,LL b) { LL s=1,base=a; while(b) { if(b&1)s=s*base%mod; base=base*base%mod; b>>=1; } return s; } LL cal(LL a,LL b) { if(a<mod&&b<mod) { if(b>a)return 0; return p[a]*pow_mod(p[b],mod-2)%mod*pow_mod(p[a-b],mod-2)%mod; } return cal(a/mod,b/mod)*cal(a%mod,b%mod)%mod; } LL solve(int L,int R) { LL fx=x[R]-x[L],fy=y[R]-y[L]; if((2*fy-fx)%3||(2*fx-fy)%3||2*fy<fx||2*fx<fy)return 0; LL up=(2*fy-fx)/3,down=(fx+fy)/3; return cal(down,up); } int main() { init(); int Case=0; while(scanf("%lld%lld%d",&n,&m,&r)!=EOF) { memset(dp,0,sizeof(dp)); int flag=0; x[0]=1,y[0]=1; for(int i=1;i<=r;i++) { scanf("%lld%lld",&x[i],&y[i]); if(x[i]==n&&y[i]==m)flag=1; } LL ans=0; if(!flag) { x[0]=1,y[0]=1; dp[0]=1; x[++r]=n,y[r]=m; for(int i=1;i<=r;i++) { for(int j=1;j<=i;j++) { if(x[j]>=x[i]&&y[j]>=y[i])swap(x[i],x[j]),swap(y[i],y[j]); } } for(int i=1;i<=r;i++)dp[i]=solve(0,i); for(int i=1;i<=r;i++) { for(int j=1;j<i;j++) { if(x[j]<=x[i]&&y[j]<=y[i])dp[i]=(dp[i]-dp[j]*solve(j,i)%mod+mod)%mod; } } for(int i=1;i<=r;i++)if(x[i]==n&&y[i]==m)ans=dp[i]; } printf("Case #%d: %lld\n",++Case,ans); } return 0; }
hdu-5794 A Simple Chess(容斥+lucas+dp)
标签:turn frame pid swa ref can init tom class
原文地址:http://www.cnblogs.com/zhangchengc919/p/6286327.html