#include <stdio.h>
using namespace std;
 
int n;
int cache[10000001];
 
int dp(int x){
    if(x == 1)
        return 0;
    
    if(cache[x] > 0)
        return cache[x];
    
    cache[x] = dp(x-1+ 1;
    
    if(x%2 == 0){
        int temp = dp(x/2+ 1;
        if(cache[x] > temp)
            cache[x] = temp;
    }
    
    if(x%3 == 0){
        int temp = dp(x/3+ 1;
        if(cache[x] > temp)
            cache[x] = temp;
    }
    
    return cache[x];
}
 
int main(){
    scanf("%d"&n);
    
    printf("%d", dp(n));
    
    return 0;
}

cs


'백준' 카테고리의 다른 글

[C++] 백준(BAEKJOON) 1005  (0) 2019.03.23
[C++] 백준(BAEKJOON) 2579  (0) 2019.03.18
[C++] 백준(BAEKJOON) 1149  (0) 2019.03.13
[C++] 백준(BAEKJOON) 1003  (0) 2019.03.13
[C++] 백준(BAEKJOON) 11726  (0) 2019.03.13

+ Recent posts