xiaoxin juju needs help
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 665 Accepted Submission(s): 196
Problem Description
As we all known, xiaoxin is a brilliant coder. He knew **palindromic** strings when he was only a six grade student at elementry school.
This summer he was working at Tencent as an intern. One day his 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 will give him a watermelon candy. The problem is how many candies xiaoxin's leader needs to buy?
This summer he was working at Tencent as an intern. One day his 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 will 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≤20) which
represents the number of test cases.
For each test case, there is a single line containing a stringS(1≤length(S)≤1,000) .
For each test case, there is a single line containing a string
Output
For each test case, print an integer which is the number of watermelon candies xiaoxin's leader needs to buy after mod 1,000,000,007 .
Sample Input
3 aa aabb a
Sample Output
1 2 1
Source
Recommend
wange2014 | We have carefully selected several similar problems for you: 5654 5653 5650 5649 5648
可以统计每个字符出现的个数,然后分别除以2,也就是对回文串的一半进行排列组合
#include <iostream> #include <string.h> #include <stdlib.h> #include <algorithm> #include <math.h> #include <stdio.h> #include <map> using namespace std; const __int64 mod=1e9+7; char a[1005]; int t; int res[1005]; map<char,int> m; int a1[1000][1000]; void init() { a1[1][1]=1; for(int i=2;i<=600;i++) { for(int j=1;j<=i;j++) { if(j==1) a1[i][j]=1; else if(j==i) a1[i][j]=1; else a1[i][j]=(a1[i-1][j]+a1[i-1][j-1])%mod; } } } int main() { int t; scanf("%d",&t); while(t--) { scanf("%s",a); int len=strlen(a); m.clear(); int tag=0; //cout<<m[a[1]]<<endl; for(int i=0;i<len;i++) { m[a[i]]++; } int cnt=1; init(); memset(res,0,sizeof(res)); __int64 sum=0; for(int i=0;i<len;i++) { if(m[a[i]]==-1) continue; if(m[a[i]]&1) tag++; res[cnt++]=(m[a[i]])/2; sum+=(m[a[i]])/2; m[a[i]]=-1; } if(tag==1&&(!(len&1))) { printf("0 "); continue; } if(tag>=2) { printf("0 "); continue; } __int64 num=1; for(int i=1;i<cnt;i++) { num=(num*a1[sum+1][res[i]+1])%mod; sum-=res[i]; } printf("%I64d ",num); } return 0; }