Adam’s parents put up a sign that says “CONGRATULATIONS”. The sign is so big that exactly one letter fits on each panel. Some of Adam’s younger cousins got bored during the reception and decided to rearrange the panels. How many unique ways can the panels be arranged (counting the original arrangement)?
Input
The first line of input is a single non-negative integer. It indicates the number of data sets to follow. Its value will be less than 30001.
    Each data set consists of a single word, in all capital letters.
    Each word will have at most 20 letters. There will be no spaces or other punctuation.
    The number of arrangements will always be able to fit into an unsigned long int. Note that 12! is the largest factorial that can fit into an unsigned long int.
Output
For each word, output the number of unique ways that the letters can be rearranged (counting the original arrangement). Use the format shown in Sample Output, below.
Sample Input
3
HAPPY
WEDDING
ADAM
Sample Output
Data set 1: 60
Data set 2: 2520
Data set 3: 12

问题链接:UVA10338 Mischievous Children
问题简述:给定字符串,计算其字母重排的数量(不同单词的数量)。
问题分析:先根据字母数量算出全排列,然后去除同一字母的重复排列。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10338 Mischievous Children */#include <bits/stdc++.h>using namespace std;typedef long long LL;
const int N = 20 + 1;
char s[N];
int cnt[26];LL fact(int n)
{long long ret = 1LL;for (int i = 2 ; i <= n ; i++)ret *= i;return ret;
}int main()
{int n;scanf("%d", &n);for(int k = 1; k <= n; k++) {scanf("%s", s);memset(cnt, 0, sizeof(cnt));LL ans = fact(strlen(s));for(int i = 0; s[i]; i++)cnt[s[i] - 'A']++;for(int i = 0; i < 26; i++)if(cnt[i]) ans /= fact(cnt[i]);printf("Data set %d: %lld\n", k, ans);}return 0;
}

UVA10338 Mischievous Children【组合数学】相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. 不畏浮云遮望眼--离散数学和组合数学

    不畏浮云遮望眼,基础很重要! 离散数学是算法和数据结构的基础,而算法和数据结构又是什么的基础?不解释了. 1.<离散数学及其应用> 作者: (美)Kenneth H. R 出版社: 机械工 ...

  3. jQuery API之each、children、index的使用

    each 参数: function: 回调函数:函数参数为index, ele(DOM元素) 作用: 循环遍历jQ数组 code: <ul><li></li>< ...

  4. szucodeforce训练1081C组合数学lucas定理,div2 627的D dfs +剪枝优化,697D Puzzles{dfs序+概率}

    给你n个方格排成一行,有m种颜色,然后要把这n个方格分成k+1段,每段涂不同的颜色,问有多少种方法. 组合数学Lucas定理 排列组合问题,首先要在n-1个位置里面选出k个位置当作段与段的分割点,然后 ...

  5. 【数学专题】组合数学与计数

    整理的算法模板合集: ACM模板 目录 AcWing 1307. 牡牛和牝牛(递推) AcWing 1308. 方程的解 AcWing 1309. 车的放置(组合数学,分类讨论) AcWing 131 ...

  6. 组合数学实验——二分图匹配算法

    2019独角兽企业重金招聘Python工程师标准>>> 大一时候写的代码,忽然翻了出来.... 算法:组合数学中文第4版 机械工业出版社 P234 ID就先隐藏掉了 // // // ...

  7. Maven报错解决:Element 'dependency' cannot have character [children], because the type's content type is

    在用maven的时候遇到报错: Element 'dependency' cannot have character [children], because the type's content ty ...

  8. Sequence(组合数学,集合不同元素的个数)

    Sequence [组合数学] 时间限制: 3 Sec  内存限制: 128 MB 提交: 138  解决: 52 [提交][状态][讨论版] 题目描述 在某个夜黑月高的晚上,!!!,原谅我编不下去了 ...

  9. eclipse 怎么关闭 show children

    eclipse 关闭 show children 前段时间使用eclipse时,误按了 shift+alt+B结果弹出了"show children"的栏目,这下让我在编写代码时总 ...

最新文章

  1. 单语言表征如何迁移到多语言去?
  2. eclipse 安装jetty时遇到的问题
  3. QT的QQmlContext类的使用
  4. 华为云桌面盒子不支持分屏_华为MatePad Pro 5G旗舰平板国内正式发布 售价5299元起...
  5. 波形分析--串口数据
  6. cocos2d-x中的尺寸之二
  7. Mac实践--MAC搭建FTP服务器
  8. 计算机教育部一级学科,教育部学科门类,一级学科有多少个?
  9. DS-5 Streamline
  10. 基于ssh的会议室管理系统(源码免费下载)
  11. C语言atoi和atol函数详解和示例
  12. 正则匹配中文、繁体字、不常见中文
  13. 【计算机网络】传输层 : 传输层概述 ( 设备层级 | 传输层功能 | TCP 协议 | UDP 协议 | 复用与分用 | 端口号 | 套接字 )
  14. macd金叉股共振_股票MACD金叉什么意思
  15. 系统性谈谈软件可靠性——第4讲:软件可靠性测试
  16. 开源软件之screen的第一次使用
  17. 【Java】虚拟机JVM
  18. acwing 217.绿豆蛙的归宿
  19. 西瓜皮——被丢掉的真金白银,夏天的健康守护神
  20. cs无限僵尸服务器,CS1.6僵尸版

热门文章

  1. 发现 nios2-elf-gcc 一处 bug
  2. 开源GIS(五)——openlayers中interaction的select、draw与modify
  3. 创建类(点击获得位置信息)—ArcGIS API for JavaScript
  4. linux下播放wma格式,Ubuntu 20.04中使Rhythmbox支持WMA格式文件播放
  5. linux 脚本 if then,shell学习之if-then语法
  6. java关键字super_Java关键字(六)——super
  7. java内存溢出前端_【面试笔录】内存溢出和内存泄漏
  8. Yarn和SparkAlone对比
  9. python更改数据框指定位置的数据_python – 移动数据框列并更改列顺序
  10. socket()编程简介