-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCTDL013.cpp
63 lines (57 loc) · 973 Bytes
/
SCTDL013.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
57
58
59
60
61
62
63
/**
* @file SCTDL013.cpp
* @author long ([email protected])
* @brief C++ implementation of generating nCk of the number N
* @version 0.1
* @date 2023-02-26
*
* @copyright Copyright (c) 2023
*
*/
#include <bits/stdc++.h>
using namespace std;
int t, k, n, X[15];
bool check = true;
void Result()
{
for (int i = 1; i <= k; i++)
{
cout << X[i];
}
cout << " ";
}
void combination(int n, int k)
{
int i = k;
while(i > 0 && X[i] == n-k+i)
i--;
if(i > 0)
{
X[i] = X[i] + 1;
for(int j = i+1; j <= k; j++)
{
X[j] = X[i] + j - i;
}
}
else check = false;
}
int main()
{
cin >> t;
while (t--)
{
cin >> n >> k;
for(int i=1; i <= k; i++)
{
X[i] = i;
}
while(check)
{
Result();
combination(n, k);
}
check = true;
cout << endl;
}
return 0;
}