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 |
Tags
- Unreal Engine 5
- 정렬
- 브루트포스
- DFS
- 백준
- 우선순위 큐
- 백트래킹
- 구현
- 그래프
- 스택
- XR Interaction Toolkit
- 수학
- 유니티
- c++
- 투 포인터
- 유니온 파인드
- 자료구조
- 다익스트라
- 누적 합
- 재귀
- 그리디 알고리즘
- 알고리즘
- ue5
- 시뮬레이션
- VR
- BFS
- Team Fortress 2
- 트리
- 다이나믹 프로그래밍
- 문자열
Archives
- Today
- Total
1일1알
백준 10974번 모든 순열 C++ 본문
https://www.acmicpc.net/problem/10974
10974번: 모든 순열
N이 주어졌을 때, 1부터 N까지의 수로 이루어진 순열을 사전순으로 출력하는 프로그램을 작성하시오.
www.acmicpc.net
백트래킹
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
vector<int> ans;
vector<bool> visited;
void BT(int size) {
if (size >= n) {
for (auto a : ans) cout << a << " ";
cout << "\n";
return;
}
for (int i = 1; i <= n; i++) {
if (visited[i]) continue;
visited[i] = true;
ans.push_back(i);
BT(size + 1);
visited[i] = false;
ans.pop_back();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
visited = vector<bool>(n + 1, false);
BT(0);
}
'알고리즘' 카테고리의 다른 글
백준 14271번 그리드 게임 C++ (0) | 2022.10.14 |
---|---|
백준 17352번 여러분의 다리가 되어 드리겠습니다! C++ (0) | 2022.10.12 |
백준 2056번 작업 C++ (0) | 2022.10.10 |
백준 5397번 키로거 C++ (0) | 2022.10.09 |
백준 1699번 제곱수의 합 C++ (0) | 2022.10.08 |