-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCTDL064.cpp
56 lines (49 loc) · 827 Bytes
/
SCTDL064.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//nCk
#include <bits/stdc++.h>
#define MAX 50
#define ll long long
#define MODULO 1e9 + 7
using namespace std;
int arr[MAX];
int n, k;
ll gt(int n) {
ll s = 1;
for (int i = 1; i <= n; i++)
s *= i;
return s;
}
ll sumKey(int n, int k) {
return gt(n) / (gt(k)*gt(n - k));
}
void res() {
cout << "[";
for (int i = 1; i <= k; i++){
cout << arr[i];
if(i < k) cout << " ";
}
cout << "]";
cout << endl;
}
void key(int i) {
for (int j = arr[i-1] + 1; j <= n-k+i; j++)
{
arr[i] = j;
if (i == k) {
res();
}
else{
key(i + 1);
}
}
}
int main() {
int t;
cin >> t;
while(t--)
{
cin >> n >> k;
cout << sumKey(n, k) << endl;
key(1);
}
return 0;
}