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 ...
随机推荐
-
Random number
Original #include <stdlib.h> #include <time.h> srand(time(NULL)); rand(); The versions o ...
-
bsearch
在java中为了避免 low+high溢出,可以用无符号右移:正数高位补0,负数高位补1 int mid = (low + high) >>> 1; 如果是在c++中,那么需要先转换 ...
-
knockoutjs表格增加更新删除
<!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...
-
ArcGis:vs c#编程遇到问题The specified filename is invalid
出现这个问题总归一点那就是你没有添加一个控件axLicenseControl这个控件导致报这个错误
-
Visual Studio 2012 编译C++显示cl命令
为了用newlisp来实现VC编译,以便用我的Emacs开发VC程序,而不需要再打开VS 2012, 需要自己实现命令行的编译.我不需要nmake,因为我想直接了解VC编译器,以便今后更好的驾驭它. ...
-
关于ECSHOP模板架设的服务器php版本过高报错的解决方法(二)
ECShop安装之后,在后台发现一个错误,这个错误提示的意思:mktime()方法不带参数被调用时,会被抛出一个报错提示. ECShop安装之后,在后台发现一个错误提示: Strict Standar ...
-
关于MongoDB数据库中文件唯一性的问题
※重要※——介绍一下我的环境:MongoDB的“win32-x86_64-2008plus-ssl-3.0.5”,MongoVUE版本是1.6.9,VS2010,dll是1.10版本. MongoDB ...
-
Flask最强攻略 - 跟DragonFire学Flask - 第二篇 Flask 中的 Render Redirect HttpResponse
1.Flask中的HTTPResponse 在Flask 中的HttpResponse 在我们看来其实就是直接返回字符串 2.Flask中的Redirect 每当访问"/redi" ...
-
Unity shader学习之逐像素漫反射光照模型
shader如下: Shader "Custom/Diffuse Fragment-Level" { Properties { _Diffuse (,,,) } SubShader ...
-
ACdream 1025 bfs
Transform Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit St ...