369 - Combinations
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=305
Computing the exact number of ways thatNthings can be takenMat a time can be a great challenge whenNand/orMbecome very large. Challenges are the stuff of contests. Therefore,
you are to make just such a computation given the following:
GIVEN:
Compute theEXACTvalue of:
You may assume that the final value ofCwill fit in a 32-bit Pascal LongInt or a C long.
For the record, the exact value of 100! is:
93,326,215,443,944,152,681,699,238,856,266,700,490,715,968,264,381,621,
468,592,963,895,217,599,993,229,915,608,941,463,976,156,518,286,253,
697,920,827,223,758,251,185,210,916,864,000,000,000,000,000,000,000,000
Input and Output
The input to this program will be one or more lines each containing zero or more leading spaces, a value forN, one or more spaces, and a value forM. The last line of the input file will contain a
dummyN,Mpair with both values equal to zero. Your program should terminate when this line is read.
The output from this program should be in the form:
Nthings takenMat a time isCexactly.
Sample Input
100 6
20 5
18 6
0 0
Sample Output
100 things taken 6 at a time is 1192052400 exactly.
20 things taken 5 at a time is 15504 exactly.
18 things taken 6 at a time is 18564 exactly.
注意这句话:
“You may assume that the final value ofCwill fit in a 32-bit Pascal LongInt or a C long.”
完整代码:
/*0.022s*/
#include<cstdio>
int main()
{
int N, M, i;
double C;
while (scanf("%d%d", &N, &M), N)
{
C = 1.0;
for (i = N; i > N - M; --i) C *= (double)i;
for (i = 2; i <= M; ++i) C /= (double)i;
printf("%d things taken %d at a time is %.0f exactly.\n", N, M, C);
}
return 0;
}
分享到:
相关推荐
Combinations Calculator(排列组合计算器) 非常专业,非常简单,非常易用的组合计算器, *快速输出自定义元素集的组合输出; *快速计算组合C(n,r)值;
Chapter1PermutationsandCombinations排列和组合.pdf
算法,钱币组合。可设定钱币种类数量,找出组合种数。
这个计算器是计算C(n,r)值的。 它能够快速计算出很大很大的n和很大的r的值。 比如 C(1000000,100)的值多少? 下面看看结果: The Value R =: ...106,621,924,285,106,201,287,451,825,038,562,207,162,667,291,115,...
大师Donald E. Knuth(汉名高德纳)的著作,计算机程序设计与艺术第四卷3册:生成所有组合和分划Generating All Combinations and Permutations(中英)
数组中的返回组合使用 es6 生成器。 安装 npm install combinations-generator 要使用此包,您必须运行 node 0.11 以获取生成器支持,并且必须使用--harmony标志运行 node。 例子 var comb = require ( ...
好久没有写博客了!...一项专利其写作主体可能由两个或两个以上主体参与,各个主体又分属不同或者相同的城市,对其合作关系数量进行统计,其实就是对主体及城市进行排列组合。Python的itertools库中提供了
可变组合长度函数的想法 combinations = (items,combinationLength) -> //items = [A,B,C,D]步骤 1. 创建一个名为sublist的items副本和一个空数组作为结果。 sublist = items.slice() //[A,B,C,D]results = []步骤 2...
Combinations of IntelligentMethods and Application
#combinations-generator 此模块用于生成给定输入字符串的所有可能组合。 输入:任何有效的字符串输出:所有可能组合的数组 ##示例用法 var combinations = require ( 'combinations-generator' ) ; var result =...
颜色组合字典 一个JSON数据集,由Sanzo Wada(1883 – 1967)编写并由Seigensha Art出版的书,包含159种独特颜色的348种颜色组合(2、3和4种颜色)。 来源 此处的数据最初由Dain M. Blodorn Kim (@dblodorn)编译并...
C = COMBINATIONS(V1, V2, V3, ...Vn) 返回由向量 V1 中的第一个元素、向量 V2 中的第二个元素、向量 V3 中的第三个元素形成的组合集合,依此类推。 C 是 KxN 矩阵,其中 K 是总组合的数量,N是数量(非空)输入向量...
In this report a number of algorithms for optimal control of a double inverted pendulum on a cart(DIPC) are investigated and compared.Modeling is based on Euler-Lagrange equations derived by ...
例如,查找加起来为二十的四位数字的所有组合,并排除数字二和七。 结果将是: [8, 5, 4, 3] [8, 6, 5, 1] [9, 6, 4, 1] 这是一个非常简单的程序,只有一个类。 要编辑参数(位数、总和和要排除的位数),您只需...
1.1 Vectors and Combinations – 向量与线性组合 Column Vector – 列向量 在数学中,向量即为带有大小和方向的量。在线性代数中经由抽象化,得到更一般的向量概念。 可以将向量定义为向量空间的元素,只需满足...
因此,我们使用组合公式来找出。 换句话说,我们发现5 选择 3 。 ({1,2,3}, {1,2,4}, {1,2,5}, {1,3,4}, {1,3,5}, {1,4,5}, { 2,3,4}, {2,3,5}, {2,4,5}, {3,4,5}) 答案是10种组合。 用法 安装 npm install --...
字符串组合 此模块用于生成给定输入字符串的所有可能组合。 输入:任何有效的字符串输出:所有可能组合的数组 示例用法 var combinations = require ( 'string-combinations' ) ; var result = combinations . ...
specific Due to the large number of conceivable combinations of sensing
组合套餐去做... 一个非常简单的VS Code扩展,可以在单词列表之间生成所有可能的组合。 选择要合并的列表所在的行,然后按Cmd + Maj + P并选择命令“生成组合”。 可选,您可以通过以下方式添加分隔符:在行之间加上...