-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1463.java
More file actions
30 lines (25 loc) · 735 Bytes
/
BOJ1463.java
File metadata and controls
30 lines (25 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package quki.algorithm.dp;
import java.util.Arrays;
import java.util.Scanner;
public class BOJ1463 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n + 1];
int inf = 1000000000;
Arrays.fill(a, inf);
a[1] = 0;
for (int i = 1; i <= n - 1; i++) {
if (i + 1 <= n) {
a[i + 1] = Math.min(a[i] + 1, a[i + 1]);
}
if (2 * i <= n) {
a[2 * i] = Math.min(a[i] + 1, a[2 * i]);
}
if (3 * i <= n) {
a[3 * i] = Math.min(a[i] + 1, a[3 * i]);
}
}
System.out.println(a[n]);
}
}