유명한 하노이 문제이다.
재귀로 푸는게 일반적인 방법인것 같다.
#include <string>
#include <vector>
using namespace std;
vector<vector<int>> hanoi;
void Hanoi(int start, int end, int n) {
if (n == 1)
{
hanoi.push_back({ start, end });
return;
}
Hanoi(start, 6 - start - end, n - 1);
hanoi.push_back({ start, end });
Hanoi(6 - start - end, end, n - 1);
}
vector<vector<int>> solution(int n) {
vector<vector<int>> answer;
Hanoi(1, 3, n);
answer = hanoi;
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV3 N으로 표현 (0) | 2022.06.13 |
|---|---|
| [프로그래머스] (C++) LV2 N-Queen (0) | 2022.06.11 |
| [프로그래머스] (C++) LV2 줄 서는 방법 (0) | 2022.06.10 |
| [프로그래머스] (C++) LV2 숫자 블록 (0) | 2022.06.10 |
| [프로그래머스] (C++) LV2 멀리 뛰기 (0) | 2022.06.09 |