HDU 5651 xiaoxin juju needs help 水题一发
分析:求一下组合数
首先,如果不止一个字符出现的次数为奇数,则结果为0。
否则,我们把每个字符出现次数除2,也就是考虑一半的情况。
那么结果就是这个可重复集合的排列数了。 fact(n)/fact(a_1)/fact(a_2)/..../fact(a_n)fact(n)/fact(a1)/fact(a2)/..../fact(an)。
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=1e3+;
const int INF=0x3f3f3f3f;
const LL mod=1e9+;
LL c[N>>][N>>];
void init(){
for(int i=;i<=;++i)c[i][]=;
for(int i=;i<=;++i)
for(int j=;j<=;++j)
c[i][j]=(c[i-][j-]+c[i-][j])%mod;
}
char s[N];
int a[];
int main(){
init();
int T;
scanf("%d",&T);
while(T--){
scanf("%s",s+);
int l=strlen(s+);
for(int i=;i<;++i)a[i]=;
for(int i=;i<=l;++i)
a[s[i]-'a']++;
int cnt=,x;
for(int i=;i<;++i)
if(a[i]%)++cnt,x=i;
if(cnt){
if(l%){
if(cnt>){
printf("0\n");
continue;
}
else --a[x];
}
else{
printf("0\n");
continue;
}
}
else{
if(l%){
printf("0\n");
continue;
}
}
LL ans=;
l>>=;
for(int i=;i<;++i){
if(!a[i])continue;
a[i]>>=;
ans=(ans*c[l][a[i]])%mod;
l-=a[i];
}
printf("%I64d\n",ans);
}
return ;
}
HDU 5651 xiaoxin juju needs help 水题一发的更多相关文章
- 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 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 (组合数)
xiaoxin juju needs helpTime Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64uSu ...
- 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 xiaoxin juju needs help 逆元模板
http://acm.hdu.edu.cn/showproblem.php?pid=5651 题意:生成回文串.输出所有回文串的可能数. 题解:mod除法会损失高位,用逆元来代替除法,模板如下 ac代 ...
- HDU 5651 xiaoxin juju needs help
组合数杨辉三角打表,这样避免了除法求逆元. #include<cstdio> #include<cstring> #include<cmath> #include& ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- [HDU 2602]Bone Collector ( 0-1背包水题 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...
- hdu 2117:Just a Numble(水题,模拟除法运算)
Just a Numble Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- memcached全面剖析--5
memcached的应用和兼容程序 mixi案例研究 mixi在提供服务的初期阶段就使用了memcached. 随着网站访问量的急剧增加,单纯为数据库添加slave已无法满足需要,因此引入了memca ...
- Windows phone 8 安装在 VMWare上错误的各种解决方案
http://windowsasusual.blogspot.jp/2013/01/how-to-launch-windows-phone-8-emulator.html Hardware requi ...
- php开学之环境搭建
1. php版本选择 1.1 PHP非线程安全与线程安全版本的选择技巧 1.2 版本区别 PHP的大版本主要分三支:PHP4/PHP5/PHP6 其中,PHP4由于太古老.对QQ支持不力已基本被淘汰, ...
- Ms SQLServer中的Union和Union All的使用方法和区别
Ms SQLServer中的Union和Union All的使用方法和区别 SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 ...
- C#中的lock关键字(初识)
http://kb.cnblogs.com/page/88513/ 首先给出MSDN的定义: lock 关键字可以用来确保代码块完成运行,而不会被其他线程中断.这是通过在代码块运行期间为给定对象获取互 ...
- ViewController 之间设置转场动画
AddOrEditViewController *addOrEdit = [[AddOrEditViewController alloc] init]; CATransition *transitio ...
- windows azure programing
http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-get-started-vs2012/ http:// ...
- hdu 1021 Fibonacci Again(找规律)
http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others ...
- python中数据的保存
1.将list中的数据写入到excel文件中 利用python包numpy(实现方式应该有许多种,这里只是记录成功实现的一种)中的savetxt 局限性:要保存的list可以为[1,2,3,4,5]这 ...
- asp.net 简单实现禁用或启用页面中的某一类型的控件
我们在提交一个表单的时候,可能由于网络或服务器的原因,处理很慢,而用户在处理结果出来之前反复点击按钮提交.这样很容易造成不必要的麻烦甚至是错误.说了这么多,其实就是要实现一个禁用某些控件的一种功能.好 ...