BOJ1463

김현민·2021년 3월 4일
0

Algorithm

목록 보기
32/126
post-thumbnail

BOJ1463 1로 만들기

문제

코드

#include <bits/stdc++.h>

using namespace std;
int d[1000001];
int main(int argc, char const *argv[])
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;

    cin >> n;
    d[1] = 0;
    for (int i = 2; i <= n; i++)
    {
        d[i] = d[i - 1] + 1;
        if (i % 2 == 0)
            d[i] = min(d[i], d[i / 2] + 1);
        if (i % 3 == 0)
            d[i] = min(d[i], d[i / 3] + 1);
    }
    cout << d[n];

    return 0;
}
profile
Jr. FE Dev

0개의 댓글