-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ14916.java
More file actions
29 lines (29 loc) · 918 Bytes
/
BOJ14916.java
File metadata and controls
29 lines (29 loc) · 918 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
import java.io.*;
import java.util.*;
public class BOJ14916 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] dp = new int[100001];
dp[1] = -1;
dp[2] = 1;
dp[3] = -1;
dp[4] = 2;
dp[5] = 1;
for (int i = 6; i <= n; i++) {
dp[i] = Integer.MAX_VALUE;
}
for (int i = 6; i <= n; i++) {
if (dp[i-2] == -1 && dp[i-5] == -1) {
dp[i] = -1;
} else if (dp[i-2] == -1) {
dp[i] = dp[i-5] + 1;
} else if (dp[i-5] == -1) {
dp[i] = dp[i-2] + 1;
} else {
dp[i] = Math.min(dp[i-2], dp[i-5]) + 1;
}
}
System.out.print(dp[n]);
}
}