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