#include <string> #include <vector> using namespace std; vector<vector<int>> answer; void hanoi(int num, int from, int by, int to) { // 1번판(마지막 원판) -> 3번판 if(num == 1) { vector<int> temp; temp.push_back(from); temp.push_back(to); answer.push_back(temp); return; } // 1번판 -> 2번판 hanoi(num-1, from, to, by); // 1번판 -> 3번판 vector<int> temp; temp.push_back(from); temp.push_back(to); answer.push_back(temp); // 2번판 -> 3번판 hanoi(num-1, by, from, to); } vector<vector<int>> solution(int n) { hanoi(n, 1, 2, 3); return answer; } | cs |
'Programmers > Level 3' 카테고리의 다른 글
[프로그래머스 3] 여행경로 (C/C++) (★) (0) | 2020.01.09 |
---|---|
[프로그래머스 3] 단어 변환 (C/C++) (0) | 2020.01.09 |
[프로그래머스 3] 네트워크 (C/C++) (0) | 2020.01.09 |
[프로그래머스 3] 이중 우선순위 큐 (C/C++) (0) | 2020.01.08 |
[프로그래머스 3] 베스트 앨범 (C/C++) (★) (0) | 2020.01.07 |