hdu5651 Xiaoxin JuJu needs help (multi-set full array + inverse)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.