Skip to content

Commit e09b54a

Browse files
authored
[20251130] BOJ / G5 / 캡틴 이다솜 / 이인희
1 parent e0168ab commit e09b54a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int N = Integer.parseInt(br.readLine());
9+
List<Integer> tetra = new ArrayList<>();
10+
for(int k=1; ; k++){
11+
// 총알 개수
12+
int t = k * (k + 1) * (k + 2) / 6;
13+
if(t > N)
14+
break;
15+
tetra.add(t);
16+
}
17+
int size = tetra.size();
18+
19+
20+
int[] dp = new int[N + 1];
21+
Arrays.fill(dp, Integer.MAX_VALUE);
22+
dp[0] = 0;
23+
for(int i = 0; i < size; i++){
24+
int t = tetra.get(i);
25+
for(int x = t; x <= N; x++){
26+
if(dp[x - t] != Integer.MAX_VALUE){
27+
dp[x] = Math.min(dp[x], dp[x-t] + 1);
28+
}
29+
}
30+
}
31+
System.out.println(dp[N]);
32+
}
33+
}
34+
35+
```

0 commit comments

Comments
 (0)