题目:
找出n个自然数(1,2···n)中取r个数的组合,例如当n=5,r=3时所有组合为
1 2 31 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
此题只需求出组合数的个数
输入描述:
5 3
20 18
输出描述:
10
190
#include <iostream>
using namespace std;
int main(){
int m, i, j, n;
int M = 1, N = 1;
cin >> m >> n;
if(m - n < n){
n = m - n;
}
for(i = 1; i <= n; i++){
M = M * m;
m = m - 1;
}
for(j = 1; j <= n; j++){
N = N * j;
}
cout << M / N;
}