๋ฌธ์
https://www.acmicpc.net/problem/15665
์ฝ๋
#include <iostream>
#include <vector>
#include <algorithm>
#define max 8
using namespace std;
int N, M;
int arr[max];
bool visited[max];
vector<int>v;
void dfs(int start) {
if (start == M) {
for (int i = 0; i < M; i++) {
cout << arr[i] << ' ';
}
cout << "\n";
}
else {
for (int i = 1; i <= v.size()-1; i++) {
arr[start] = v[i - 1];
dfs(start + 1);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) {
int num; cin >> num;
v.push_back(num);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end()-1);
dfs(0);
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 9625๋ฒ - BABBA (0) | 2021.12.29 |
---|---|
[๋ฐฑ์ค,c++] 15688๋ฒ - ์ ์ ๋ ฌํ๊ธฐ5 (0) | 2021.12.14 |
[๋ฐฑ์ค,c++] 15666๋ฒ - N๊ณผ M (12) (0) | 2021.12.04 |
[๋ฐฑ์ค,c++] 15664๋ฒ - N๊ณผ M (10) (0) | 2021.12.04 |
[๋ฐฑ์ค,c++] 15663๋ฒ - N๊ณผ M (9) (0) | 2021.12.04 |
[๋ฐฑ์ค,c++] 15657๋ฒ - N๊ณผ M (8) (0) | 2021.12.04 |
๋๊ธ