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 |
Tags
- 컴퓨터공학과
- 코딩
- DP
- 오에스
- 컴공과
- vector
- coding
- 너비우선탐색
- 개발
- 백준
- 자료구조
- 컴공
- 알고리즘
- Stack
- bfs
- Operating System
- 구현
- 정석
- 정석학술정보관
- 북리뷰
- 문제풀이
- OS
- 스택
- cs
- 브루트포스
- 코테
- c++
- 그래프
- Computer science
- 오퍼레이팅시스템
Archives
- Today
- Total
Little Jay
[C++] 백준 15650번 - N과 M(2) 본문
백트래킹에 들어가있지만,
DFS로 풀 수 있는것 같다.
둘이 조금은 비슷한 성향을 가진 문제인 것 같다.
#include <iostream>
#include <cstring>
#define MAX 9
using namespace std;
int n, m;
int arr[MAX] = { 0, };
bool visited[MAX] = { 0, };
void dfs(int num, int cnt) {
if (cnt == m) {
for (int i = 0; i < m; i++)
cout << arr[i] << ' ';
cout << '\n';
return;
}
for (int i = num; i <= n; i++) {
if (!visited[i]) {
visited[i] = true;
arr[cnt] = i;
dfs(i + 1, cnt + 1);
visited[i] = false;
}
}
}
int main() {
cin >> n >> m;
dfs(1, 0);
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 15652번 - N과 M (4) (0) | 2021.11.06 |
---|---|
[C++] 백준 15651번 - N과 M (3) (0) | 2021.11.06 |
[C++] 백준 7875번 - Brackets (0) | 2021.09.26 |
[C++] 백준 1712번 - 손익분기점 (0) | 2021.09.25 |
[C++] 백준 10808번 - 알파벳 개수 (0) | 2021.09.25 |
Comments