The combination number Yang Hui the triangular table, thus avoids the division to seek the inverse element.
#include <cstdio>#include<cstring>#include<cmath>#include<queue>#include<algorithm>using namespacestd;Const Long LongMod=1000000007;Const intmaxn= ++Ten;Long LongC[MAXN][MAXN];inttot[ -];CharS[MAXN];voidinit () {c[1][1]=1; for(intI=1; i<= +; i++) c[i][0]=1; for(intI=2; i<= +; i++) { for(intj=1; j<= +; j + +) {C[i][j]= (c[i-1][j-1]+c[i-1][J])%MOD; } }}intMain () {intT; Init (); scanf ("%d",&T); while(t--) {scanf ("%s", s); memset (Tot,0,sizeoftot); for(intI=0; s[i];i++) tot[s[i]-'a']++; intnum=0; for(intI=0;i< -; i++) if(tot[i]%2==1) num++; if(num>1) printf ("0\n"); Else { intsum=0; Long Longans=1; for(intI=0;i< -; i++) sum=sum+Tot[i]; if(num==1) { for(intI=0;i< -; i++)if(tot[i]%2==1) tot[i]--; Sum--; } for(intI=0;i< -; i++) { if(tot[i]==0|| sum==0)Continue; Ans= (ans*c[sum/2][tot[i]/2])%MOD; Sum=sum-Tot[i]; } printf ("%lld\n", ans); } } return 0;}
HDU 5651 xiaoxin JuJu needs help