HDU 5651 逆元
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
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?
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)
.
.
#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 逆元的更多相关文章
- HDU 5651 计算回文串个数问题(有重复的全排列、乘法逆元、费马小定理)
原题: http://acm.hdu.edu.cn/showproblem.php?pid=5651 很容易看出来的是,如果一个字符串中,多于一个字母出现奇数次,则该字符串无法形成回文串,因为不能删减 ...
- HDU - 5651 xiaoxin juju needs help 逆元模板
http://acm.hdu.edu.cn/showproblem.php?pid=5651 题意:生成回文串.输出所有回文串的可能数. 题解:mod除法会损失高位,用逆元来代替除法,模板如下 ac代 ...
- HDU 5651 xiaoxin juju needs help 逆元
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5651 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- HDU 5651 组合+逆元
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5651 题目意思我看了半天没读懂,一直以为是回文子串又没看见substring的单词最后看博客才知道是用给 ...
- hdu 5651 xiaoxin juju needs help 逆元 两种求解方式
xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- hdu 5651 重复全排列+逆元
知识点: n个元素,其中a1,a2,····,an互不相同,进行全排列,可得n!个不同的排列. 若其中某一元素ai重复了ni次,全排列出来必有重复元素,其中真正不同的排列数应为 ,即其重复度为ni! ...
- HDU 5651 xiaoxin juju needs help 数学
xiaoxin juju needs help 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5651 Description As we all k ...
- HDU 5651 xiaoxin juju needs help
组合数杨辉三角打表,这样避免了除法求逆元. #include<cstdio> #include<cstring> #include<cmath> #include& ...
- hdu 1211 逆元
RSA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- Siki_Unity_0_Unity A计划直播视频
Unity A计划直播视频 2017-07-04直播 任务1:如何识别以招聘来招培训生的公司: 打着招聘的旗号帮培训机构找培训生 关键词:实训生 任务2:如何识别一个公司的好坏和规模大小: 猎聘(中高 ...
- Java学习笔记-10.io流
1.输入流,只能从中读取数据,而不能向其写出数据.输出流,只能想起写入字节数据,而不能从中读取. 2.InputStream的类型有: ByteArrayInputStream 包含一个内存缓冲区,字 ...
- win32绘制自定义类窗口导致绘制11个窗口的解决办法
上网查了一圈也没有找到解决问题的办法,一旦创建了一个窗口,并且在过程函数中绘制窗口,尤其是一些非子窗口的自定义类窗口,都会生成11个窗口(算上主窗口就是12个),但是使用系统通用控件就不会有这种情况的 ...
- numpy切片和布尔型索引
numpy 标签(空格分隔): numpy 数据挖掘 切片 数组切片是原始数组的视图.这意味着数据不会被复制,视图上的任何修改都会直接反映到源数组上 In [16]: arr Out[16]: arr ...
- Sublime Text 插件推荐——for web developers
楼主向高大上的: web front-end development engineer (好吧,google就是这样翻译的 ^_^)们推荐 ST 插件,在此抛砖引玉: NO.1 :Emmet (原名: ...
- 为什么23种设计模式中没有MVC
GoF (Gang of Four,四人组, <Design Patterns: Elements of Reusable Object-Oriented Software>/<设计 ...
- Martian Addition
In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are ...
- 软件工程第二周PSP
- ajax 返回值问题
错误示例:function returnFlag(){ $.ajax({ type:"post", dataType:"json", data:JSON.str ...
- javaweb引用jar类库的问题
JAVAWEB中,需要引用的jar类库必须放在/WebContent/WEB-INF/lib文件夹中.不然就会各种报错.