-
Notifications
You must be signed in to change notification settings - Fork 0
/
DSA01004-Sinh_To_Hop.cpp
48 lines (41 loc) · 1.16 KB
/
DSA01004-Sinh_To_Hop.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
//https://github.com/tminoshy
//created by Đỗ Thiện Minh in 07/09/2024
#include <iostream>
#include <vector>
using namespace std;
void generateCombinations(const vector<int> &numbers, vector<int> ¤tCombination, int total, int index) {
if(currentCombination.size() == total) {
for (const int &value : currentCombination) {
cout << value;
}
cout << " ";
return;
}
if(index == numbers.size()) {
return;
}
currentCombination.push_back(numbers[index]);
generateCombinations(numbers, currentCombination, total, index + 1);
currentCombination.pop_back();
generateCombinations(numbers, currentCombination, total, index + 1);
}
void Testcase() {
int N, K;
cin >> N >> K;
vector<int> currentCombination;
vector<int> numbers(N);
for (size_t i = 0; i < N; i++) {
numbers[i] = i + 1;
}
generateCombinations(numbers, currentCombination, K, 0);
cout << endl;
}
int main() {
int testCount; cin >> testCount;
while(testCount--) {
Testcase();
}
return 0;
}
//B23DCCE064
//SINH TỔ HỢP