본문 바로가기
Coding Test/Programmers

[Programmers] Lv 2. 숫자 변환하기

by song.ift 2023. 7. 20.

https://school.programmers.co.kr/learn/courses/30/lessons/154538

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <string>
#include <vector>
#include <map>

using namespace std;

void search(int x, int y, int n, int count, vector<int>& v)
{
    if (v[x] && count >= v[x]) return;
    
    v[x] = count;

    if (x + n <= y) search(x + n, y, n, count + 1, v);
    if (x * 2 <= y) search(x * 2, y, n, count + 1, v);
    if (x * 3 <= y) search(x * 3, y, n, count + 1, v);
}

int solution(int x, int y, int n) {
    if (x == y) return 0;
    
    vector<int> v(y, 0);
    search(x, y, n, 0, v);
    return !v[y] ? -1 : v[y];
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/commit/529f0767736c6268e960ed141a7cabede65e666a

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글