Skip to content

Commit

Permalink
2024-05-11 1로만들기
Browse files Browse the repository at this point in the history
  • Loading branch information
dhlee777 committed May 10, 2024
1 parent 0529f80 commit 175a26d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dhlee777/dp/1로만들기.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<iostream>
using namespace std;
int dp[1000001];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int num;
cin >> num;
dp[1] = 0;
dp[2] = 1;
dp[3] = 1;
for (int i = 4; i <= num; i++) {
dp[i] = dp[i - 1] + 1;
if (i % 3 == 0)
dp[i] = min(dp[i], dp[i / 3] + 1);
if (i % 2 == 0)
dp[i] = min(dp[i], dp[i / 2] + 1);
}
cout << dp[num];

}

0 comments on commit 175a26d

Please sign in to comment.