Xiaoxin JuJu needs help
Test instructions: give you a string to find out how many palindrome strings are thrown after the characters are scrambled. (at the end of the text)
Knowledge Points:
n elements, in which a1,a2,,an are different, are arranged in a full order, and can be n! in various permutations.
If one of the elements Ai repeats ni times, the entire arrangement must have repeating elements, where the true difference in the number of permutations should be, that is, the repetition of ni!
Similarly A1 repeats N1 times, A2 repeats N2 times,,ak repeats nk times, n1+n2+ +nk=n.
For such n elements to be arranged in a full order, the number of different permutations is actually
Exercises
The string length is Len, and if each element repeats ni as an odd number of count>1, it cannot form a palindrome string.
When it is possible to make a palindrome, we only need to consider the left half of the palindrome, so this problem becomes a duplicate full permutation of half the string.
Because it involves the problem of the division to take the mold, so use the inverse element.
The inverse can be extended by Euclidean or Ma Xiao theorem. /*6. Inverse element */
#include <iostream> #include <cstdio> #include <cstring>using namespace std;typedef long Long ll;const LL mod=1e9+7;int Cnt[260];char ch[1005]; LL Jiecheng (int n) {if (n==0) return 1; LL Ans=1; for (int i=1;i<=n;i++) Ans=ans*i%mod; return ans;} LL x, y; ll GCD (ll A,ll b) {ll t,d; if (b==0) {x=1,y=0; return A; } d=gcd (B,A%B); T=x, X=y, y=t-(A/b) *y; return D; }int Main () {int t; cin>>t; while (t--) {memset (cnt,0,sizeof (CNT)); scanf ("%s", ch); int Len=strlen (CH); for (int i=0;i<len;i++) {cnt[ch[i]-']++; } int count=0; for (int i=0;i<260;i++) {if (cnt[i]&1) count++; cnt[i]/=2; } if (count>1) {cout<<0<<endl; Continue } LL Ans=jiecheng (LEN/2)%mod; for (int i=0;i<260;i++) {if (Cnt[i]>0) {gcd (Jiecheng (Cnt[i]), MOD); if (x<0) X+=mod; Ans=ans*x%mod; }} cout<<ans<<endl; }}
Xiaoxin JuJu needs help
Time limit:1000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64u
Submit Status
Description
As we all known, Xiaoxin is a brilliant coder. He knew **palindromic** strings when he is only a six grade student at Elementry School.
This summer he is working at Tencent as an intern. One day he leader came to ask Xiaoxin for help. His leader gave him a string and he wanted Xiaoxin to generate palindromic strings for him. Once Xiaoxin generates a different palindromic string, his leader would give him a watermelon candy. The problem is how many candies Xiaoxin ' s leader needs to buy?
Input
This problem has multi test cases. First line contains a single integer $T (T\LEQ) $ which represents the number of test cases.
For each test case, the there is a single line containing a string $S (1 \leq Length (S) \leq 1,000) $.
Output
For the all test case, print a integer which is the number of watermelon candies Xiaoxin ' s leader needs to buy after MoD $ $, 000,000,007$.
Sample Input
Sample Output
hdu5651 Xiaoxin JuJu needs help (multi-set full array + inverse)