分析:求一下组合数

首先,如果不止一个字符出现的次数为奇数,则结果为0。

否则,我们把每个字符出现次数除2,也就是考虑一半的情况。

那么结果就是这个可重复集合的排列数了。 fact(n)/fact(a_1)/fact(a_2)/..../fact(a_n)fact(n)/fact(a​1​​)/fact(a​2​​)/..../fact(a​n​​)。

#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 水题一发的更多相关文章

  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 helpTime Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64uSu ...

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

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

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

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

  6. HDU 5651 xiaoxin juju needs help

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

  7. HDU 2096 小明A+B --- 水题

    HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...

  8. [HDU 2602]Bone Collector ( 0-1背包水题 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...

  9. hdu 2117:Just a Numble(水题,模拟除法运算)

    Just a Numble Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. 鼠标事件(window.onload的自己的错误)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. rhel_6.x 安装mysql

    不知为何mysql的官网很难下载,本人网上找了好久,终于找到了个镜像: 特别感谢http://mirrors.sohu.com/mysql/MySQL-5.6/    ^_^ 首先下载mysql的下面 ...

  3. MySQL基础学习之数据查询

    一般查询 SELECT * FROM 表名 SELECT 属性名  FROM  表名 条件查询 SELECT 属性名 FROM 表名  WHERE 条件表达式 查询数据值1,数据值2的表单 SELEC ...

  4. oracle服务介绍

    按照windows 7 64位 安装oracle 11g R2中的方法成功安装Oracle 11g后,共有7个服务,这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Ser ...

  5. Ubuntu启动停止在checking battery state...

    Ubuntu在“checking battery state...”处停止了,出现这种现象的原因可能有很多种.笔者遇到的是其中的一种. 情景描述: 笔者此前将Ubuntu的图形启动方式修改为了字符界面 ...

  6. C# zip/unzip with ICSharpCode.SharpZipLib

    download ICSharpCode and add reference using System; using System.Collections.Generic; using System. ...

  7. sencha touch

    download http://www.sencha.com/products/touch/thank-you/ Developer Center http://developer.sencha.co ...

  8. DB天气app冲刺第四天

    今天卡壳了 做得很慢.. 明天继续 换一种思路试一下吧..

  9. python 读取机器信息

    本人最近新学python ,用到关于机器的相关信息,经过一番研究,从网上查找资料,经过测试,总结了一下相关的方法. # -*- coding: UTF8 -*- import os import wi ...

  10. Ollydbg 中断方法浅探

    Ollydbg是一个新的32位的汇编层调试软件.适应于windows98.me.2000.xp和2003操作系统.由于他具有图形窗口界面,所以操作方便.直观,是cracker的好工具. 由于Ollyd ...