Data Structure & Algorithm: Level-1 Problem #60. Factorial and Combination-1

In mathematics, a combination is a selection of items from a collection, such that the order of selection does not matter (unlike permutations). To choose m items from a total item of n, the formula for combination is as follows:

Combination Formula

Given N football teams (8 <= N <= 32), and each team will play m ( 2 <= m <=4 ) games with any other team.

Sample Input:

N = 8, m= 3

Sample Output:

84

For 8 teams each needs to play 3 games with another team. The total games are 84.


数据结构和算法:初级练习题 #60 阶乘和组合(一)


组合(combination),数学的重要概念之一。从n个不同元素中每次取出m个不同元素(0≤m≤n),不管其顺序合成一组,称为从n个元素中不重复地选取m个元素的一个组合。所有这样的组合的总数称为组合数,这个组合数的计算公式为

Combination Formula

给定N支足球队 (8 <= N <= 32),每支球队都需要和其他每个球队比赛m场 ( 2 <= m <=4 ),计算总共有多少场比赛。

输入样例

N = 8, m= 3

输出样例:

84

八支球队相互之间都需要比赛三场,总共的比赛是84场。


Python Solution

Factorial and Combination