HDU 5651 xiaoxin juju needs help (组合数)
xiaoxin juju needs help
Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d &
%I64u
Submit
Status
Description
As we all known, xiaoxin is a brilliant coder. He knew **palindromic** strings when he was
only a six grade student at elementry school.
This summer he was working at Tencent as an intern. One day his leader came to ask xiaoxin
for help. His leader gave him a string and he wanted xiaoxin to generate palindromic
strings for him. Once xiaoxin generates a different palindromic string, his leader will
give him a watermelon candy. The problem is how many candies xiaoxin's leader needs to
buy?
Input
This problem has multi test cases. First line contains a single integer T(T\leq 20) which
represents the number of test cases.
For each test case, there is a single line containing a string S(1 \leq length(S) \leq
1,000).
Output
For each test case, print an integer which is the number of watermelon candies xiaoxin's
leader needs to buy after mod 1,000,000,007.
Sample Input
3
aa
aabb
a
Sample Output
1
2
1
Source
BestCoder Round #77 (div.2)
给你n个字母,求可以组成的回文串的个数
只有满足以下条件才可以组成回文串。
1.n为奇数,有一个字母的个数为奇数
2.n为偶数,字母个数全为偶数
然后将字母的个数num[i]/2,得出在对称轴左边的个项字母的个数
假设左边有len个字母,如果每个字母都不同则有len!中可能
然后除去所有重复的可能num[i]!即可
因为除法取模 (len!/num[i]!)%mod
#include <iostream>
#include <cstring>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll c[][];
void get()
{
memset(c,,sizeof(c));
c[][]=; //会涉及到
for(int i=;i<=;i++)
{
c[i][]=;
c[i][]=i;
}
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
c[i][j]=(c[i-][j]+c[i-][j-])%mod;
}
int main()
{
get();
int t;
cin>>t;
while(t--)
{
char str[];
int a[];
memset(a,,sizeof(a));
cin>>str; //不要重复定义c
int len=strlen(str);
for(int i=;i<len;i++)
a[str[i]-'a']++;
int flag=-;
for(int i=;i<;i++)
{
if(a[i]%)
flag++;
a[i]/=;
}
//cout<<flag<<endl;
if(flag>=) //注意 -1 为真!!!
{
cout<<<<endl; //输出一个正整数的时候前面不能加0 否则会错
}
else
{
len/=;
//cout<<len<<a[0]<<a[1]<<endl;
ll ans=;
for(int i=;i<;i++)
{
ans=ans*c[len][a[i]]%mod;
len-=a[i];
}
cout<<ans<<endl;
}
}
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 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 ...
- HDU 5651 xiaoxin juju needs help
组合数杨辉三角打表,这样避免了除法求逆元. #include<cstdio> #include<cstring> #include<cmath> #include& ...
- 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/ ...
随机推荐
- 【BZOJ-1965】SHUFFLE 洗牌 快速幂 + 拓展欧几里德
1965: [Ahoi2005]SHUFFLE 洗牌 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 541 Solved: 326[Submit][St ...
- BZOJ-1975 魔法猪学院 K短路 (A*+SPFA)
1975: [Sdoi2010]魔法猪学院 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1323 Solved: 433 [Submit][Statu ...
- 学习笔记--函数式线段树(主席树)(动态维护第K极值(树状数组套主席树))
函数式线段树..资瓷 区间第K极值查询 似乎不过似乎划分树的效率更优于它,但是如果主席树套树状数组后,可以处理动态的第K极值.即资瓷插入删除,划分树则不同- 那么原理也比较易懂: 建造一棵线段树(权值 ...
- angularjs的页面拆分思想
//app.js angular.module('MyModule', ['SubModule1', 'SubModule2']) .module('SubModule1', ['CommonModu ...
- bzoj2096 pilots
依旧是维护两个单调队列,只是队首检查的方式略有变动 /*by SilverN*/ #include<iostream> #include<algorithm> #include ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 在myeclipse10.7.1中写代码有很多红x
代码没问题,但是很多代码前都有红x.在doc中执行都没有问题 jdk版本不对应 //第一步:菜单栏Window--Preferences--Java--Installed JREs--右边Add ...
- JAVA的面向对象编程--------课堂笔记
面向对象主要针对面向过程. 面向过程的基本单元是函数. 什么是对象:EVERYTHING IS OBJECT(万物皆对象) 所有的事物都有两个方面: 有什么(属性):用来描述对象. 能够做什么 ...
- Linux VPS新硬盘分区与挂载教程
通过fdisk -l我们可以看到/dev/xvdb(此名称因系统而异)容量有23.6G,而且没有分区,接下来我们对它进行分区和挂载 (红色字为需要输入的部分,黑色字为系统显示部分) 1.fdisk - ...
- 安装coreseek找不到mysql
1.安装 coreseek-3.2.14 遇到问题:“ERROR: cannot find MySQL include files,随即在网上搜索各种答案说是要找到mysql.h的正确路径加入./co ...