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
- C++
- Set
- N과M
- 배열
- 깊이우선탐색
- priority_queue
- DP
- 에라토스테네스의 체
- 우선순위큐
- int
- Sort
- 문자열
- 최소공배수
- 오블완
- 백트래킹
- 알고리즘
- 분할정복
- map
- 백준
- vector
- 프로그래머스
- 다이나믹프로그래밍
- 그래프
- DFS
- 이분탐색
- 정렬
- stoi
Archives
- Today
- Total
안녕 세상아,
[c++/백준] 10974 모든 순열 본문
https://www.acmicpc.net/problem/10974
10974번: 모든 순열
N이 주어졌을 때, 1부터 N까지의 수로 이루어진 순열을 사전순으로 출력하는 프로그램을 작성하시오.
www.acmicpc.net
전형적인 백트래킹 문제이다.
N과 M 문제 풀어봤으면 걍 눈 감고도 풀기 가능하다.
https://hello-world-cpp.tistory.com/2
[백준/c++] 15649 N과 M(1)
https://www.acmicpc.net/problem/15649 전형적인 백트래킹 문제,, DFS를 참고해서 풀면 된다. 중복도 허용하기 때문에 백트래킹계의 순열이라고 볼 수 있다. DFS의 재귀를 이용하여 풀었다. 자세한 설명은 코
hello-world-cpp.tistory.com
여기 더 자세하게 코드 설명 해놨다. 너무 똑같아서 코드 설명 따로 할게 없다.
#include <iostream>
#include <algorithm>
using namespace std;
int arr[10];
bool isVisited[10] = { false };
int n;
void backTracking(int depth) {
if (depth == n) {
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << '\n';
}
for (int i = 1; i <= n; i++) {
if (!isVisited[i]) {
isVisited[i] = true;
arr[depth] = i;
backTracking(depth + 1);
isVisited[i] = false;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
backTracking(0);
}
그치만 어쩌면 나는 문제 답을 외워버렸을지도..?
'백준' 카테고리의 다른 글
[c++/백준] 2579 계단 오르기 (1) | 2023.05.12 |
---|---|
[c++/백준] 1004 어린 왕자 (0) | 2023.05.12 |
[c++/백준] 15654 N과 M (5) (0) | 2023.05.11 |
[c++/백준] 14425 문자열 집합 (0) | 2023.05.11 |
[c++/백준] 9375 패션왕 신해빈 (0) | 2023.05.11 |