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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<queue>
  5. #include<algorithm>
  6. using namespace std;
  7.  
  8. const long long MOD=;
  9. const int maxn=+;
  10. long long c[maxn][maxn];
  11. int tot[];
  12. char s[maxn];
  13.  
  14. void init()
  15. {
  16. c[][]=;
  17. for(int i=;i<=;i++) c[i][]=;
  18. for(int i=;i<=;i++)
  19. {
  20. for(int j=;j<=;j++)
  21. {
  22. c[i][j]=(c[i-][j-]+c[i-][j])%MOD;
  23. }
  24. }
  25. }
  26.  
  27. int main()
  28. {
  29. int T;
  30. init();
  31. scanf("%d",&T);
  32. while(T--)
  33. {
  34. scanf("%s",s);
  35. memset(tot,,sizeof tot);
  36. for(int i=;s[i];i++) tot[s[i]-'a']++;
  37.  
  38. int num=;
  39. for(int i=;i<;i++)
  40. if(tot[i]%==) num++;
  41.  
  42. if(num>) printf("0\n");
  43. else
  44. {
  45. int sum=;
  46. long long ans=;
  47. for(int i=;i<;i++) sum=sum+tot[i];
  48. if(num==)
  49. {
  50. for(int i=;i<;i++) if(tot[i]%==) tot[i]--;
  51. sum--;
  52. }
  53. for(int i=;i<;i++)
  54. {
  55. if(tot[i]==||sum==) continue;
  56. ans=(ans*c[sum/][tot[i]/])%MOD;
  57. sum=sum-tot[i];
  58. }
  59. printf("%lld\n",ans);
  60. }
  61. }
  62. return ;
  63. }

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. codeforces 689B Mike and Shortcuts 最短路

    题目大意:给出n个点,两点间的常规路为双向路,路长为两点之间的差的绝对值,第二行为捷径,捷径为单向路(第i个点到ai点),距离为1.问1到各个点之间的最短距离. 题目思路:SPFA求最短路 #incl ...

  2. 过滤器HttpModule

    1.建一个类库文件  FirsModule,实现IHttpModule接口,实现其中的两个方法,写一函数实现自己的代码逻辑,在Init方法中调用即可. // <summary> /// 第 ...

  3. 修改apache配置文件去除thinkphp url中的index.php

    例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index. ...

  4. robot framework -记录关键字

    1.set value if (当条件满足时,进行变量赋值) 2.focus (将焦点定在制定的元素) 3.win close +title(关闭制定title) 4.get list items  ...

  5. URAL 2099 Space Invader题解 (计算几何)

    啥也不说了,直接看图吧…… 代码如下: #include<stdio.h> #include<iostream> #include<math.h> using na ...

  6. MySQL 5.7 for Windows 解压缩版配置安装

    从MYSQL5.7.6开始,安装MYSQL提示“请键入 NET HELPMSG 3534 以获得更多的帮助”的解决办法 今天安装MySQL提示如下错误: ----------------------- ...

  7. 第19章 网络通信----TCP程序设计基础

    TCP网络程序设计是指利用Socket类编写通信程序.利用TCP协议进行通信的两个应用程序是有主次之分的,一个称为服务器程序,另一个称为客户机程序,两者的功能和编写方法大不一样. 1.InetAddr ...

  8. Ubuntu root 密码设置及远程登录

    1. 修改 root 密码 sudo passwd root 2. 以其他账户登录,通过 sudo nano 修改 /etc/ssh/sshd_config : xxx@ubuntu14:~$ su ...

  9. TCP/IP Protocol Fundamentals Explained with a Diagram

    最近准备系统学习网络相关的知识,主要学习tcp/ip, websocket 知识. 原文地址:http://www.thegeekstuff.com/2011/11/tcp-ip-fundamenta ...

  10. didMoveToSuperView 引发的思考

    1. - (void)didMoveToSuperview 通知视图已经移动到一个新的父视图中 2. /**系统自动调用(留给子类去实现)**/ - (void)didAddSubview:(UIVi ...