hdu 5651
来源:互联网 发布:淘宝手机端详情页gif 编辑:程序博客网 时间:2024/06/08 08:22
xiaoxin juju needs help
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1376 Accepted Submission(s): 392
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
3aaaabba
Sample Output
121
Source
BestCoder Round #77 (div.2)
Recommend
wange2014
有点类似于组合,用杨辉三角与二项式系数的关系打出一个表。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int c[1005][1005];int main(){ int cnt[1005],ch[1005],T; char S[1005]; c[0][0]=1; c[1][0]=c[1][1]=1; for(int i=2;i<1005;i++) { c[i][0]=c[i][i]=1; for(int j=1;j<i;j++) { c[i][j]=c[i-1][j-1]+c[i-1][j]; if(c[i][j]>=1000000007) { c[i][j]%=1000000007; } } } scanf("%d",&T); while(T--) { scanf("%s",S); memset(cnt,0,sizeof(cnt)); int k=0,flag=0,sum=0; long long ans=1; for(int i=0;i<strlen(S);i++) { if(!cnt[S[i]]) { ch[k++]=S[i]; } cnt[S[i]]++; } for(int i=0;i<k;i++) { if(cnt[ch[i]]%2==1) { sum+=cnt[ch[i]]/2; flag++; } else { sum+=cnt[ch[i]]/2; } cnt[ch[i]]/=2; } if(flag>1) { printf("0\n"); continue; } for(int i=0;i<k;i++) { if(cnt[ch[i]]==0) { continue; } else { ans*=c[sum][cnt[ch[i]]]; sum-=cnt[ch[i]]; if(ans>1000000007) { ans%=1000000007; } } } printf("%I64d\n",ans); } return 0;}
0 0
- HDU 5651
- hdu 5651
- hdu 5651
- HDU 5651
- hdu 5651
- HDU 5651组合数
- HDU 5651 (组合 水~)
- hdu 5651 反省
- HDU 5651 组合数学
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- 二叉树中最大最小权值节点距离问题
- iOS中图片缓存策略
- NYOJ矩形嵌套
- chrome内核浏览器,排版错位
- [Android]自定义简易版日历控件
- hdu 5651
- Android 属性动画(Property Animation) 完全解析
- 机器学习ML简史
- JOptionPane类提示框的一些常用的方法
- ffmpeg: 视频转码命令例子
- iOS开发上传图片的压缩
- php加密方法
- android自定义UI组件
- Intellij IDEA常用配置详解