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

#include <iostream>
#include <cstring>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll c[][];
void get()
{
memset(c,,sizeof(c));
c[][]=; //会涉及到
for(int i=;i<=;i++)
{
c[i][]=;
c[i][]=i;
}
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
c[i][j]=(c[i-][j]+c[i-][j-])%mod;
}
int main()
{
get();
int t;
cin>>t;
while(t--)
{
char str[];
int a[];
memset(a,,sizeof(a));
cin>>str; //不要重复定义c
int len=strlen(str);
for(int i=;i<len;i++)
a[str[i]-'a']++;
int flag=-;
for(int i=;i<;i++)
{
if(a[i]%)
flag++;
a[i]/=;
}
//cout<<flag<<endl;
if(flag>=) //注意 -1 为真!!!
{
cout<<<<endl; //输出一个正整数的时候前面不能加0 否则会错
}
else
{
len/=;
//cout<<len<<a[0]<<a[1]<<endl;
ll ans=;
for(int i=;i<;i++)
{
ans=ans*c[len][a[i]]%mod;
len-=a[i];
}
cout<<ans<<endl;
}
}
return ;
}

HDU 5651 xiaoxin juju needs help (组合数)的更多相关文章

  1. HDU 5651 xiaoxin juju needs help 逆元

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5651 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  2. HDU 5651 xiaoxin juju needs help 数学

    xiaoxin juju needs help 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5651 Description As we all k ...

  3. hdu 5651 xiaoxin juju needs help 逆元 两种求解方式

    xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  4. HDU - 5651 xiaoxin juju needs help 逆元模板

    http://acm.hdu.edu.cn/showproblem.php?pid=5651 题意:生成回文串.输出所有回文串的可能数. 题解:mod除法会损失高位,用逆元来代替除法,模板如下 ac代 ...

  5. HDU 5651 xiaoxin juju needs help 水题一发

    分析:求一下组合数 首先,如果不止一个字符出现的次数为奇数,则结果为0. 否则,我们把每个字符出现次数除2,也就是考虑一半的情况. 那么结果就是这个可重复集合的排列数了. fact(n)/fact(a ...

  6. HDU 5651 xiaoxin juju needs help

    组合数杨辉三角打表,这样避免了除法求逆元. #include<cstdio> #include<cstring> #include<cmath> #include& ...

  7. hdu5651 xiaoxin juju needs help(逆元)

    xiaoxin juju needs help  Accepts: 150  Submissions: 966  Time Limit: 2000/1000 MS (Java/Others)  Mem ...

  8. hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)

    xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串.                      (题于文末) 知识点: n个元素,其中a1,a2,··· ...

  9. HDU 5651 逆元

    xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

随机推荐

  1. 【poj1090】 Chain

    http://poj.org/problem?id=1090 (题目链接) 题意 给出九连环的初始状态,要求将环全部取下需要走多少步. Solution 格雷码:神犇博客 当然递推也可以做. 代码 / ...

  2. App接口中xml方式封装通信接口

  3. iOS 刚刚,几分钟前,几小时前,几天前,几月前,几年前

    - (NSString *)compareCurrentTime:(NSDate*) compareDate { NSTimeInterval timeInterval = [compareDate ...

  4. Linux下使用popen()执行shell命令

    转载 http://www.cnblogs.com/caosiyang/archive/2012/06/25/2560976.html 简单说一下popen()函数 函数定义 #include < ...

  5. Android SDK安装Android4.0“冰激淋三明治”(IceCreamSandwich)教程(转载)

    昨天,Google举行了发布会,发布了Nexus Prime手机和Android4.0-IceCreamSandwich手机系统.作为Google旗下Android的最新版本手机系 统,Android ...

  6. GCC 编译详解

    GNU CC(简称为Gcc)是GNU项目中符合ANSI C标准的编译系统,能够编译用C.C++和Object C等语言编写的程序.Gcc不仅功能强大,而且可以编译如C.C++.Object C.Jav ...

  7. yum使用本地源

    cache: [k2e喜]: 注意它的发音: 不是: keik the attribute could not be removed from the cache. 不能从缓存删除属性. YUM对服务 ...

  8. VIM、GVIM在WINDOWS下中文乱码的终极解决方案

    文章转自:http://www.liuhuadong.com/archives/68 vim.gvim在windows下中文乱码的终极解决方案在windows下vim的中文字体显示并不好,所以我们需要 ...

  9. HDU4901 The Romantic Hero 计数DP

    2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...

  10. LR测试心得

    ====================测试方案—优化前—优化后 每一项至少两份报告==================================== url录制方式录制出来的脚本mode是HT ...