๋ฌธ์
https://www.acmicpc.net/problem/15657
์ฝ๋
#include <iostream>
#include <vector>
#include <algorithm>
#define max 9
using namespace std;
bool visited[max];
int arr[max];
int N, M;
vector<int>v;
void dfs(int num, int start) {
if (start == M) {
for (int i = 0; i < M; i++) {
cout << arr[i] << " ";
}
cout << "\n";
}
else {
for (int i = num; i <= N; i++) {
visited[i] = true;
arr[start] = v[i - 1];
dfs(i, start + 1);
visited[i] = false;
}
}
}
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());
dfs(1, 0);
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 15665๋ฒ - N๊ณผ M (11) (0) | 2021.12.04 |
---|---|
[๋ฐฑ์ค,c++] 15664๋ฒ - N๊ณผ M (10) (0) | 2021.12.04 |
[๋ฐฑ์ค,c++] 15663๋ฒ - N๊ณผ M (9) (0) | 2021.12.04 |
[๋ฐฑ์ค,c++] 15656๋ฒ - N๊ณผ M (7) (0) | 2021.12.04 |
[๋ฐฑ์ค,c++] 15655๋ฒ - N๊ณผ M (6) (0) | 2021.12.04 |
[๋ฐฑ์ค,c++] 15654๋ฒ - N๊ณผ M (5) (0) | 2021.12.04 |
๋๊ธ