반응형
BOJ 1463번 https://www.acmicpc.net/problem/1463
#include <iostream>
int min(int a, int b) {
return (a < b) ? a : b;
}
int main() {
int n = 0 ;
std::cin >> n;
int result[1000001];
result[1] = 0;
result[2] = result[3] = 1;
int i;
for (i = 4; i <= n; ++i) {
if (i%6 == 0) {
result[i] = min(min(result[i-1], result[i/2]),
result[i/3]) + 1;
} else if (i%2 == 0) {
result[i] = min(result[i-1],
result[i/2]) + 1;
} else if (i%3 == 0) {
result[i] = min(result[i-1],
result[i/3]) + 1;
} else {
result[i] = result[i-1] + 1;
}
}
std::cout << result[n] << std::endl;
return 0;
}
반응형
댓글