#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, 123);
    
    return answer;
}
cs

+ Recent posts