You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
727 B
42 lines
727 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
int n, k, nums[26], sel[26];
|
|
bool flag[26];
|
|
/*
|
|
6 2
|
|
1 2 2 3 4 2
|
|
|
|
1 2
|
|
1 3
|
|
1 4
|
|
2 2
|
|
2 3
|
|
2 4
|
|
3 4
|
|
*/
|
|
void dfs(int index, int min) {
|
|
if (index == k) {
|
|
for (int i = 0; i < k; i++)
|
|
cout << sel[i] << " ";
|
|
cout << endl;
|
|
return;
|
|
}
|
|
|
|
for (int i = min; i <= n; i++) {
|
|
if (nums[i] == nums[i - 1] && !flag[i - 1])
|
|
continue;
|
|
|
|
sel[index] = nums[i];
|
|
flag[i] = true;
|
|
dfs(index + 1, i + 1);
|
|
flag[i] = false;
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
cin >> n >> k;
|
|
for (int i = 1; i <= n; i++) cin >> nums[i];
|
|
sort(nums + 1, nums + n + 1);
|
|
dfs(0, 1);
|
|
return 0;
|
|
} |