File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments