BestCoder Round #77 (div.2)
2016-03-28 20:07
357 查看
xiaoxin juju needs help
[align=center]Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1124 Accepted Submission(s): 323
[/align]
提示:可重集的全排列+逆元;(板子题,)
弱渣要学逆元啦!
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?
[align=left]Input[/align]
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 string
S(1≤length(S)≤1,000).
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
3
aa
aabb
a
[align=left]Sample Output[/align]
1
2
1
[align=left]Source[/align]
BestCoder Round #77 (div.2)
[align=left]Recommend[/align]
wange2014 | We have carefully selected several similar problems for you: 5654 5653 5649 5648 5647
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #include <vector> #define LL long long using namespace std; LL A[1010]= {1,1}; int D[26]; char s[1010]; LL MOD=1e9+7; LL solve( LL x) { LL n=MOD-2; LL ans=1; while(n) { if(n&1) { (ans*=x)%=MOD; } (x*=x)%=MOD; n>>=1; } return ans; } int main() { for(LL i=2; i<1001; i++) (A[i]=A[i-1]*i)%=MOD; int t; cin>>t; while(t--) { scanf("%s",s); memset(D,0,sizeof(D)); for(int i=0; s[i]; i++) D[s[i]-'a']++; int odd=0,cnt=0; for(int i=0;i<26; i++) { if(D[i]%2) odd++; D[i]/=2; cnt+=D[i]; } if(odd>1) { printf("0\n"); continue; } LL ans=A[cnt]; for(int i=0; i<26; i++) { (ans*=(solve(A[D[i]])))%=MOD; } printf("%I64d\n",ans); } return 0; }
相关文章推荐
- BZOJ 4401(块的计数-树的划分)
- Android数据解析之XML篇
- 完整java开发中JDBC连接数据库代码和步骤
- 输出特殊符号,可以用单引号'引文':echo 'Hello World !'
- JAVA学习笔记(三)
- Contest Print Server (2013年山东省第四届ACM大学生程序设计竞赛):
- iOS UITableView 1
- 开发环境配置-eclipse插件的安装与卸载-3
- javascript
- robustMatch
- 删除系统多余引导项(msconfig中无引导项信息)
- Educational Codeforces Round 10 D. Nested Segments
- 求和
- 简述什么是T-SQL
- Android Studio 环境配置
- JSON 中JsonConfig的使用
- java.lang.nullpointerexceptiond的原因
- 绘制斜线的方法
- 【HDOJ 5652】xiaoxin juju needs help(排列组合)
- Unity UGUI实现图文混排