Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- dfs
- ์๋ฎฌ๋ ์ด์
- dynamic debugging
- ๊ตฌํ
- web
- CVE
- Spring
- BFS
- error
- java
- ์ฐ์ ์์ ํ
- ์์ ์ ๋ ฌ
- GCP
- ๊ทธ๋ฆฌ๋
- Reversing
- ๋ฐ์ดํฌ์คํธ๋ผ
- ์ต๋จ ๊ฒฝ๋ก
- ๋ฌธ์์ด
- ๋งต
- ์ด๋ถ ํ์
- ์คํ
- thymeleaf
- OS
- ๋์ ํฉ
- ๋ฐฑํธ๋ํน
- DP
- JPA
- c++
- ์ฌ๊ท
- ๋ถํ ์ ๋ณต
Archives
- Today
- Total
hades
15654๋ฒ: N๊ณผ M (5) ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/15654
๐ ์ค๊ณ
์ ํ์ ์ธ ๋ฐฑํธ๋ํน ๋ฌธ์ ์ด๋ค. ์ฌ์ ์์ผ๋ก ์ถ๋ ฅํด์ผ ํ๋ฏ๋ก, ์ค๋ฆ์ฐจ์ ์ ๋ ฌ ํ, ๋ฐฑํธ๋ํน์ ์ฌ์ฉํ๋ฉด ๋๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, m;
vector<int> number(8);
vector<bool> visited(8);
vector<int> temp;
void bt(int count) {
if (count == m) {
for (int i = 0; i < m; i++) {
cout << temp[i] << " ";
}
cout << "\n";
}
for (int i = 0; i < n; i++) {
if (!visited[i]) {
visited[i] = true;
temp.push_back(number[i]);
bt(count + 1);
temp.pop_back();
visited[i] = false;
}
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> number[i];
}
sort(number.begin(), number.begin() + n);
bt(0);
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 15666๋ฒ: N๊ณผ M (12) (0) | 2024.08.13 |
---|---|
[Baekjoon] 2638๋ฒ: ์น์ฆ (0) | 2024.08.13 |
[Baekjoon] 9465๋ฒ: ์คํฐ์ปค (0) | 2024.08.11 |
[Baekjoon] 2096๋ฒ: ๋ด๋ ค๊ฐ๊ธฐ (0) | 2024.08.10 |
[Baekjoon] 1987๋ฒ: ์ํ๋ฒณ (0) | 2024.08.09 |