组合数杨辉三角打表,这样避免了除法求逆元。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std; const long long MOD=;
const int maxn=+;
long long c[maxn][maxn];
int tot[];
char s[maxn]; void init()
{
c[][]=;
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;
}
}
} int main()
{
int T;
init();
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
memset(tot,,sizeof tot);
for(int i=;s[i];i++) tot[s[i]-'a']++; int num=;
for(int i=;i<;i++)
if(tot[i]%==) num++; if(num>) printf("0\n");
else
{
int sum=;
long long ans=;
for(int i=;i<;i++) sum=sum+tot[i];
if(num==)
{
for(int i=;i<;i++) if(tot[i]%==) tot[i]--;
sum--;
}
for(int i=;i<;i++)
{
if(tot[i]==||sum==) continue;
ans=(ans*c[sum/][tot[i]/])%MOD;
sum=sum-tot[i];
}
printf("%lld\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 水题一发

    分析:求一下组合数 首先,如果不止一个字符出现的次数为奇数,则结果为0. 否则,我们把每个字符出现次数除2,也就是考虑一半的情况. 那么结果就是这个可重复集合的排列数了. fact(n)/fact(a ...

  7. hdu5651 xiaoxin juju needs help(逆元)

    xiaoxin juju needs help  Accepts: 150  Submissions: 966  Time Limit: 2000/1000 MS (Java/Others)  Mem ...

  8. hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)

    xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串.                      (题于文末) 知识点: n个元素,其中a1,a2,··· ...

  9. HDU 5651 逆元

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

随机推荐

  1. linux 终端相关

    echo cd ~/桌面 >> .bashrc 将终端默认路径设为桌面 -/.bashrc./etc/bash.bashrc./etc/profile这几个文件.这些文件的的作用时机:/e ...

  2. Temporary exceptions can be configured via your app's Info.plist file.

    报错: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure ...

  3. 从市场运营角度谈Uber中国的第一批用户是怎么来的

    声明:这篇文章是从http://www.010lm.com/redian/2016/0312/1206875.html转来的,分享给大家. 1)首先告诉用户Uber是做什么的?即培养用户品牌意识. 我 ...

  4. Java-枚举介绍

    需求:今天遇到一个问题,就是返回某些固定的int值,要用到枚举. 下面开始介绍: 无参构造方法的枚举 enum Color{ YELLOW,BLUE,RED } 解析:首先Color本身是一个枚举,里 ...

  5. 灵感闪现 篇 (一) 2d场景 3d 效果

    中途打断一下 ,框架文档的 更新. 另开一篇主题为 灵感闪现的 板块. 在工作生活中,总有发现新事物或新东西 而让自己突然 灵感闪现的时候,那么这个时候,我必须要抓住,并尽快把 这份灵感实现下来. 之 ...

  6. POJ - 3061 Subsequence(连续子序列和>=s的最短子序列长度)

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  7. PAT1015

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  8. 【PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异常】

    public static void main(String[] args) throws IOException { /** * PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异 ...

  9. 使用nodejs的net模块创建TCP服务器

    使用nodejs的net模块创建TCP服务器 laiqun@msn.cn Contents 1. 代码实现 2. 使用telnet连接服务器测试 3. 创建一个TCP的client 1. 代码实现 ; ...

  10. 单片AT89C2051 + SD卡 + 3310LCD = 音乐播放器

    http://www.amobbs.com/thread-4503884-1-1.html 这个小玩意,采用 ATMEL 的传统51MCU作主控制芯片,加上SD卡和显示屏,就可以作简单的音乐播放器了, ...