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

#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. FileSystemXmlApplicationContext方法的绝对路径问题

    public AgentServer(Socket c,String confDir) { this.client = c; ApplicationContext ac = new FileSyste ...

  2. 安卓常用 widget

    验证码 public class SpinnerImg extends ImageView { /** * 完成选择后启动另外一个spinner */ private ItemListener ite ...

  3. 在Javascript中使用protobuf与c++进行通信

    环境:Win7_64旗舰版,VS2013 最近在研究Webkit,已经编译成功,接下来就是Javascript与c++如何传输数据,立刻就想到了protobuf,但是谷歌不支持Javascript,百 ...

  4. 几个SQL语句笔试题

    1.表A和表B具有完全相同的结构,查出表A中有但表B中没有的数据: create table A( id int , name ), password ) ); create table B( id ...

  5. Python基础学习3---数据结构

    数据结构 数据结构基本上就是---他们是可以处理数据的结构或者说他们是用来存储一组相关数据的. 在python中有三种内建的数据结构-----列表.元组和字典 列表(list) 列表就像是我们要去超市 ...

  6. Ubuntu下安装使用MongoDB

    安装 官网下载: https://www.mongodb.org/ 解压解包 重命名为mongodb 移动到/usr/local/目录下 创建连个软连接  ln -s /usr/local/mongo ...

  7. CentOS-Desktop版service network restart报错

    出错情况: [root@localhost]# service network restart正在关闭接口 eth0: 设备状态:3 (断开连接)                            ...

  8. C++头文件#include<bits/stdc++.h>

    一句话的事,直截了当——#include<bits/stdc++.h>包含C++的所有头文件 参考网站(点击):http://www.tuicool.com/articles/m6neUj ...

  9. Centos修改默认网卡名

    安装系统后默认的网卡名称为 enpXX ,修改为熟悉的eth0 1 vi /etc/default/grub GRUB_TIMEOUT=5GRUB_DEFAULT=savedGRUB_DISABLE_ ...

  10. [转] Spring Security(01)——初体验

    [转自:http://haohaoxuexi.iteye.com/blog/2154299] 首先我们为Spring Security专门建立一个Spring的配置文件,该文件就专门用来作为Sprin ...