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 ...
随机推荐
- spring 中的<aop:advisor>和<aop:aspect>的区别
在AOP中有几个概念: — 方面(Aspect):一个关注点的模块化,这个关注点实现可能另外横切多个对象.事务管理是J2EE应用中一个很好的横切关注点例子.方面用Spring的Advisor或拦截器实 ...
- DataGridView默认不选中
NurseGridList.CurrentCell = null; NurseGridList.ClearSelection(); Nurs ...
- WPF异步调用WCF服务
wpf调用wcf时,第一次访问总耗时到达几秒,影响界面的用户体验,因此在wpf加载界面和加载数据时采用异步加载,即异步访问wcf服务, 由于是否采用异步加载和服务端无关,仅仅由客户端自己根据需要来选择 ...
- php 魔术方法__get()和__set()理解
__get()方法,官方手册上是这样解释的 : ' 当调用(自己加的:或设置|赋值)当前环境下未定义或不可见的类属性或方法时,重载方法会被调用.本节后面将使用"不可访问属性(inaccess ...
- Drupal commerce 性能优化
从开始的时候打开一个页面需要超过9秒的时间到现在可以在3秒内打开,给自己带来了很多欣慰. 开始的时候是认为server性能不足,所以讲aliyun服务器从1核升级到了4核,但是发现升级之后和升级之前是 ...
- wpf 只在window是ShowDialog打开时才设置DialogResult
//only set DialogResult when window is ShowDialog before if(System.Windows.Interop.ComponentDispatch ...
- ibatis访问oracle数据库US7ASCII中文乱码问题
今天碰到一个问题,使用ibatis框架访问编码为US7ASCII的oracle数据中文乱码, 找了很久终于有了解决方案 首先 SqlMap-Config.xml按如下配置 <sqlMapConf ...
- 一步步学习ASP.NET MVC3 (1)——基础知识
请注明转载地址:http://www.cnblogs.com/arhat 首先在这里我想声明一下,这个ASP.NET MVC3系列是我在授课过程中的一些经验,有什么不对的地方,请大家指出,我们共同的学 ...
- Jfinal 入门
Jfinal 入门 IDE----->IDEA 新建项目 新建web项目 添加maven特性 方便导入jar包,不用一个个导入了 配置pom.xml <dependencies> & ...
- python 操作sqlite数据库
'''SQLite数据库是一款非常小巧的嵌入式开源数据库软件,也就是说 没有独立的维护进程,所有的维护都来自于程序本身. 在python中,使用sqlite3创建数据库的连接,当我们指定的数据库文件不 ...