cgy12306

[백준 BoJ] 1463 - 1로 만들기 본문

Algorithm/C++

[백준 BoJ] 1463 - 1로 만들기

cgy12306 2021. 3. 25. 16:41
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int DP[1000001] = { 0, };
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int X, a, b, c;

	cin >> X;

	DP[1] = 0;
	DP[2] = 1;
	DP[3] = 1;
	for (int i = 4; i <= X; i++) {
		a = X;
		b = X;
		if (i % 2 == 0) a = DP[i / 2] + 1;
		if (i % 3 == 0) b = DP[i / 3] + 1;
		c = DP[i - 1] + 1;
		DP[i] = min({ a,b,c });
	}
	cout << DP[X];
	
}

'Algorithm > C++' 카테고리의 다른 글

[백준 BoJ] 11727 - 2xn 타일링 2  (0) 2021.03.25
[백준 BoJ] 11726 - 2xn 타일링  (0) 2021.03.25
[백준 BoJ] 1260 - DFS와 BFS  (0) 2021.03.25
[백준 BoJ] 9095 - 1, 2, 3 더하기  (0) 2021.03.25
[백준 BoJ] 1476 - 날짜 계산  (0) 2021.03.25
Comments