P1446 [HNOI2008]Cards
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int N=65; int Sr,Sb,Sg,m,p; int fac[N],ifac[N]; int ksm(int x,int k) { int res=1; while(k) { if(k&1) res=1ll*res*x%p; k>>=1; x=1ll*x*x%p; } return res; } int main() { scanf("%d%d%d%d%d",&Sr,&Sb,&Sg,&m,&p); int lim=Sr+Sb+Sg; fac[0]=1; for(int i=1;i<=lim;++i) fac[i]=fac[i-1]*i%p; ifac[lim]=ksm(fac[lim],p-2); for(int i=lim-1;~i;--i) ifac[i]=ifac[i+1]*(i+1)%p; cout<<1ll*fac[lim]*ifac[Sr]%p*ifac[Sb]%p*ifac[Sg]%p*ksm(m+1,p-2)%p; return 0; }