标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 809 Accepted Submission(s): 231
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<map> 5 #define ll __int64 6 using namespace std; 7 int n; 8 char a[1005]; 9 #define mod 1000000007 10 map<char,int> mp; 11 ll quickmod(ll a,ll b) 12 { 13 ll sum=1; 14 while(b) 15 { 16 if(b&1) 17 sum=(sum*a)%mod; 18 b>>=1; 19 a=(a*a)%mod; 20 } 21 return sum; 22 } 23 24 int main() 25 { 26 scanf("%d",&n); 27 for(int i=1;i<=n;i++) 28 { 29 mp.clear(); 30 int jishu=0; 31 int sum=0; 32 scanf("%s",a); 33 int len=strlen(a); 34 for(int j=0;j<len;j++) 35 mp[a[j]]++; 36 for(int j=‘a‘;j<=‘z‘;j++) 37 { 38 if(mp[j]%2==1) 39 { 40 jishu++; 41 } 42 } 43 if(len%2==0) 44 { 45 if(jishu!=0) 46 { 47 cout<<"0"<<endl; 48 continue;} 49 } 50 else 51 { 52 if(jishu>1) 53 {cout<<"0"<<endl; 54 continue;} 55 } 56 for(int j=‘a‘;j<=‘z‘;j++) 57 { 58 sum=sum+mp[j]/2; 59 } 60 ll ans=1; 61 ll gg=1; 62 for(int j=‘a‘;j<=‘z‘;j++) 63 { 64 for(int k=1;k<=mp[j]/2;k++) 65 gg=gg*k%mod; 66 67 } 68 for(int j=1;j<=sum;j++) 69 { 70 ans=ans*j%mod; 71 } 72 printf("%I64d\n",(ans*(quickmod(gg,mod-2)%mod))%mod); 73 } 74 return 0; 75 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5325677.html