HDU 5651 xiaoxin juju needs help
组合数杨辉三角打表,这样避免了除法求逆元。
#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的更多相关文章
- 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 水题一发
分析:求一下组合数 首先,如果不止一个字符出现的次数为奇数,则结果为0. 否则,我们把每个字符出现次数除2,也就是考虑一半的情况. 那么结果就是这个可重复集合的排列数了. fact(n)/fact(a ...
- hdu5651 xiaoxin juju needs help(逆元)
xiaoxin juju needs help Accepts: 150 Submissions: 966 Time Limit: 2000/1000 MS (Java/Others) Mem ...
- hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)
xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串. (题于文末) 知识点: n个元素,其中a1,a2,··· ...
- HDU 5651 逆元
xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
随机推荐
- HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...
- easyui实现权限管理
在js中: function makeEasyTree(data){ if(!data) return []; var _newData = []; //最终返回结果 var _treeArray = ...
- LightOJ 1234 Harmonic Number 调和级数部分和
题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 Sample Input Sample Output Case : Case : ...
- HDU 1814 Peaceful Commission
2-SAT,输出字典序最小的解,白书模板. //TwoSAT输出字典序最小的解的模板 //注意:0,1是一组,1,2是一组..... #include<cstdio> #include&l ...
- hdu_4897_Little Devil I(树链剖分)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4897 题意:有三种操作,1是在树上的两个节点之间的路径改变当前的颜色,2是改变树上有且只有一个端点在u ...
- EM阅读资料
1,从最大似然到EM算法浅解 2,(EM算法)The EM Algorithm 3,数据挖掘十大算法----EM算法(最大期望算法) (番外)最大后验估计(MAP)
- Mysql 自动备份脚本
转自: Mysql 自动备份脚本2 - - ITeye技术网站http://kangh.iteye.com/blog/2309091 备份方案: 备份主机:192.168.10.11 数据库服务器:1 ...
- 以前的loginUI
的 <%@ page language="java" pageEncoding="UTF-8"%> <%@ include file=&quo ...
- hibernate事务并发问题(脏读,不可重复读,幻读)
脏读 dirty read: 读了别的事务没有提交的事务, 可能回滚, 数据可能不对. 不可重复读 non repeatable read: 同一个事务里前后读出来的数据不一样, 被另一个事务影响 ...
- Developing Backbone.js Applications
https://addyosmani.com/backbone-fundamentals/