HDU 5651 xiaoxin juju needs help (组合数)
2016-03-31 23:50
393 查看
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 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?
Input
This problem has multi test cases. First line contains a single integer T(T\leq 20) which
represents the number of test cases.
For each test case, there is a single line containing a string S(1 \leq length(S) \leq
1,000).
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
BestCoder Round #77 (div.2)
给你n个字母,求可以组成的回文串的个数
只有满足以下条件才可以组成回文串。
1.n为奇数,有一个字母的个数为奇数
2.n为偶数,字母个数全为偶数
然后将字母的个数num[i]/2,得出在对称轴左边的个项字母的个数
假设左边有len个字母,如果每个字母都不同则有len!中可能
然后除去所有重复的可能num[i]!即可
因为除法取模 (len!/num[i]!)%mod
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 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?
Input
This problem has multi test cases. First line contains a single integer T(T\leq 20) which
represents the number of test cases.
For each test case, there is a single line containing a string S(1 \leq length(S) \leq
1,000).
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
BestCoder Round #77 (div.2)
给你n个字母,求可以组成的回文串的个数
只有满足以下条件才可以组成回文串。
1.n为奇数,有一个字母的个数为奇数
2.n为偶数,字母个数全为偶数
然后将字母的个数num[i]/2,得出在对称轴左边的个项字母的个数
假设左边有len个字母,如果每个字母都不同则有len!中可能
然后除去所有重复的可能num[i]!即可
因为除法取模 (len!/num[i]!)%mod
#include <iostream> #include <cstring> using namespace std; #define mod 1000000007 typedef long long ll; ll c[505][505]; void get() { memset(c,0,sizeof(c)); c[0][0]=1; //会涉及到 for(int i=1;i<=500;i++) { c[i][0]=1; c[i][1]=i; } for(int i=2;i<=500;i++) for(int j=2;j<=i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod; } int main() { get(); int t; cin>>t; while(t--) { char str[1005]; int a[30]; memset(a,0,sizeof(a)); cin>>str; //不要重复定义c int len=strlen(str); for(int i=0;i<len;i++) a[str[i]-'a']++; int flag=-1; for(int i=0;i<26;i++) { if(a[i]%2) flag++; a[i]/=2; } //cout<<flag<<endl; if(flag>=1) //注意 -1 为真!!! { cout<<0<<endl; //输出一个正整数的时候前面不能加0 否则会错 } else { len/=2; //cout<<len<<a[0]<<a[1]<<endl; ll ans=1; for(int i=0;i<26;i++) { ans=ans*c[len][a[i]]%mod; len-=a[i]; } cout<<ans<<endl; } } return 0; }
相关文章推荐
- 读取Android sd卡的文件
- 2016年3月31日渗透学习总结
- Eclipse环境下配置spket中ExtJS提示(针对无提示和提示错误)
- 实现无锁的栈与队列
- 【C++ Primer plus】【第九章】内存模型和名称空间
- 08-maven同时下载源码
- 把自己电脑变成FTP服务器~~
- JavaCV读写包含中文路径的图片
- android获取外置SD卡的路径
- [BZOJ2461][BeiJing2011]符环(记忆化搜索)
- Java实现二叉树
- 【解题报告】Codeforces Round #303 (Div. 2)
- C++作业2:银行
- 软件测试(第三次作业)——图覆盖
- Codeforces 659E 找环+(并查集/dfs)
- 07-maven的依赖范围
- 一行 Python 实现并行化 -- 日常多线程操作的新思路
- C++第2次实验
- 获取文件行数
- iOS边练边学--触摸事件以及能够拖拽的UIView的练习