xiaoxin juju needs help

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 809    Accepted Submission(s): 231

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?

 
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 string S(1≤length(S)≤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
 
题意: 给一段只有小写字母的字符串 判断能够组合成多少种回文串
 
题解:首先,如果不止一个字符出现的次数为奇数,则结果为0。 否则,我们把每个字符出现次数除2,也就是考虑一半的情况。 那么结果就是这个可重复集合的排列数了。
A!/(n1!*n2!....)
这里直接除 会出错 需要用到逆元的知识
http://blog.csdn.net/acdreamers/article/details/8220787
另外如何求逆元?
 
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define ll __int64
using namespace std;
int n;
char a[];
#define mod 1000000007
map<char,int> mp;
ll quickmod(ll a,ll b)
{
ll sum=;
while(b)
{
if(b&)
sum=(sum*a)%mod;
b>>=;
a=(a*a)%mod;
}
return sum;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
mp.clear();
int jishu=;
int sum=;
scanf("%s",a);
int len=strlen(a);
for(int j=;j<len;j++)
mp[a[j]]++;
for(int j='a';j<='z';j++)
{
if(mp[j]%==)
{
jishu++;
}
}
if(len%==)
{
if(jishu!=)
{
cout<<""<<endl;
continue;}
}
else
{
if(jishu>)
{cout<<""<<endl;
continue;}
}
for(int j='a';j<='z';j++)
{
sum=sum+mp[j]/;
}
ll ans=;
ll gg=;
for(int j='a';j<='z';j++)
{
for(int k=;k<=mp[j]/;k++)
gg=gg*k%mod; }
for(int j=;j<=sum;j++)
{
ans=ans*j%mod;
}
printf("%I64d\n",(ans*(quickmod(gg,mod-)%mod))%mod);
}
return ;
}
 
 

HDU 5651 逆元的更多相关文章

  1. HDU 5651 计算回文串个数问题(有重复的全排列、乘法逆元、费马小定理)

    原题: http://acm.hdu.edu.cn/showproblem.php?pid=5651 很容易看出来的是,如果一个字符串中,多于一个字母出现奇数次,则该字符串无法形成回文串,因为不能删减 ...

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

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

  3. HDU 5651 xiaoxin juju needs help 逆元

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

  4. HDU 5651 组合+逆元

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5651 题目意思我看了半天没读懂,一直以为是回文子串又没看见substring的单词最后看博客才知道是用给 ...

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

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

  6. hdu 5651 重复全排列+逆元

    知识点: n个元素,其中a1,a2,····,an互不相同,进行全排列,可得n!个不同的排列. 若其中某一元素ai重复了ni次,全排列出来必有重复元素,其中真正不同的排列数应为 ,即其重复度为ni! ...

  7. HDU 5651 xiaoxin juju needs help 数学

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

  8. HDU 5651 xiaoxin juju needs help

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

  9. hdu 1211 逆元

    RSA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. TW实习日记:第28天

    同前两天一样,等接口,开发,调试接口.重复地做着低级代码得搬运工作,确实挺没意思的.怪不得有些人一直说写低级代码很无聊,没有创造性和成就感.31号准备溜了,还是好好复习准备秋招吧. 挖坑清单: Vue ...

  2. 利用maven进行项目管理

    下面为maven项目管理的一个结构 首先pom是路径文件,我们在编译或是运行程序时调用到jdk或一些自己写的jar包时会需要指明物理路径,这里的pom是一样的道理,同时在maven的管理下多出来了一些 ...

  3. mapReduce入门教程

    什么是MapReduce MapReduce是Google提出的一个软件架构,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归纳)&q ...

  4. 小猫爬山:dfs

    题目描述: 翰翰和达达饲养了N只小猫,这天,小猫们要去爬山. 经历了千辛万苦,小猫们终于爬上了山顶,但是疲倦的它们再也不想徒步走下山了(呜咕>_<). 翰翰和达达只好花钱让它们坐索道下山. ...

  5. springMVC使用拦截器检查用户登录

    参考文章 编写拦截器类 package cultivate_web.interceptor; import javax.servlet.http.HttpServletRequest; import ...

  6. 由一个hash字符串生成多个子hash字符串

    通过存储一个head hash,然后把子hash放到网络中 当然,也可以像默克尔树那样的,生成多级的子hash ,可以通过规则配置不同的hash 生成方式.倒置的默克尔树 我有一个文件,然后我把她分隔 ...

  7. 用逗号隔开简单数据保存为csv

    用记事本编辑简单数据,用英文逗号隔开,编辑为多列,保存为.csv文件.可以用Excel打开编辑.

  8. 【Docker 命令】- inspect命令

    docker inspect : 获取容器/镜像的元数据. 语法 docker inspect [OPTIONS] NAME|ID [NAME|ID...] OPTIONS说明: -f :指定返回值的 ...

  9. arp_ignore

    上一篇文件说了arp_announce,那么到这里arp_ignore,我们直接看代码应该也比较容易立即了 目前我知道的是arp_ignore = 0,只要IP是自己机器上的,都可以回复: 说实话就是 ...

  10. [OS] 线程相关知识点

    操作系统中引入进程的目的,是为了描述和实现多个程序的并发执行,以改善资源利用率以及提高系统吞吐量.那为什么还需要引入线程呢?下面我们先来回顾一下什么是进程: 进程有两个基本属性:·资源的拥有者:给每个 ...