-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj17626.java
More file actions
31 lines (25 loc) · 752 Bytes
/
boj17626.java
File metadata and controls
31 lines (25 loc) · 752 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
31
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class boj17626 {
static int[] dp;
static int min;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
dp = new int[n + 1];
dp[0] = 0;
dp[1] = 1;
solve(n);
System.out.println(dp[n]);
}
static void solve(int n) {
for (int i = 2; i <= n; i++) {
min = Integer.MAX_VALUE;
for (int j = 1; j * j <= i; j++) {
min = Math.min(min, dp[i - j * j]);
}
dp[i] = min + 1;
}
}
}