HDU 5651组合数
2016-03-26 21:58
344 查看
xiaoxin juju needs help
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1702 Accepted Submission(s): 507
[align=left]Problem Description[/align]
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[code]#include<stdio.h> #include<string.h> #define mod 1000000007 char s[1010]; int ch[30]; int c[2010][2000]; long long int q[1010]; int main() { int n,y,x,T; memset(c,0,sizeof(c)); c[0][0]=1; for(int i=1; i<=1010; i++) { c[i][0]=1; for(int j=1; j<=1010; j++) { c[i][j]=(c[i-1][j]+c[i-1][j-1])%1000000007; } } while(~scanf("%d",&T)) { while(T--) { scanf("%s",s); int k=strlen(s); memset(ch,0,sizeof(ch)); for(int i=0; i<k; i++) { ch[s[i]-'a'+1]++; } int sum=0,cn=0; int f=0; for(int i=1; i<=26; i++) { if(ch[i]) { sum+=ch[i]/2; q[cn++]=ch[i]/2; if(ch[i]%2) { f++; if(f==2) break; } } } if(f!=2) { long long ans=1; for(int i=0; i<cn; i++) { ans*=(c[sum][q[i]]%mod); ans%=mod; sum-=q[i]; } printf("%I64d\n",ans); } else printf("0\n"); } } return 0; }
[/code]
相关文章推荐
- python语法31[module/package+import]
- css3的基本内容
- 最大子数组2.0
- 状态压缩DP---Hie with the Pie
- git常用命令
- Linux之grub引导详情与故障排除
- 再写makefile
- AJAX
- cocos2d-x中文显示问题
- 3月第三四周小结(3.16~3.27)
- 第一章 第一个spring boot程序
- css的基本内容
- 修改 login的串口重定向
- Raspberry Pi Samba(Share Files With Mac OS)
- 基于BNF范式的M3中Schema板架语言的解析
- [Q]打印机页边距设置
- sqlite数据库文件导入到sqlserver
- linux下使用ccat让你的cat高亮显示
- C语言中#的神奇作用
- 菜鸟成长记-UILabel使用、横线划掉价格