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 ...
随机推荐
- linux中的sticky bit
今天看到有个目录的权限是rwxrwxrwt 很惊讶这个t是什么,怎么不是x或者-呢?搜了下发现: 这个t代表是所谓的sticky bit. sticky bit: 该位可以理解为防删除位. 一个文件是 ...
- apply()与call()的区别
一直都没太明白apply()与call()的具体使用原理,今日闲来无事,决定好好研究一番. JavaScript中的每一个Function对象都有一个apply()方法和一个call()方法,它们的语 ...
- 重力加速度陀螺仪传感器MPU-6050(一)
MPU-60X0 对陀螺仪和加速度计分别用了三个16 位的ADC,将其测量的模拟量转化 为可输出的数字量.为了精确跟踪快速和慢速的运动,传感器的测量范围都是用户可控的,陀螺仪可测范围为±250,±50 ...
- Application.StartupPath同System.Environment.CurrentDirectory区别
System.Windows.Forms.Application.StartupPath:获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称. System.Environment.Curr ...
- ECshop网店系统百万级商品量性能优化-简单的一些Cache内存配置
ECshop网店系统对于产品的数据.模板.Query都可以缓存,也就是把一些商品详情页.分类页.Search页的数据经过一次访问后,用文件的形式保存下来,下次有人访问相同的页面时,不用再查数据库,直接 ...
- Python中使用ElementTree解析xml
在Python中,ElementTree是我们常用的一个解析XML的模块 1.导入ElementTree模块 from xml.etree import ElementTree as ET 2.初始化 ...
- bootstrap form
http://getbootstrap.com/examples/starter-template/ <form class="form-horizontal" role=& ...
- 【转载】Java 升级到jdk7后DbVisualizer 6 启动空指针的处理方案
将JDK从6升级到了7(或从其他电脑移植DBV文件夹后),每当启动DbVisualizer 6的时候都会报空指针异常 在官网上找到了相关的方案,如下: In the DbVisualizer inst ...
- 实现strlen,strcpy,strcat,strcmp同功能的函数stringLength,stringCopy,stringCatch,stringCompare
#import <Foundation/Foundation.h> /* 求字符串长度 */ int stringLength(char arr[]); /* 复制字符串 将arr1 复制 ...
- 朴素贝叶斯文本分类java实现
package com.data.ml.classify; import java.io.File; import java.util.ArrayList; import java.util.Coll ...