結果
問題 | No.27 板の準備 |
ユーザー |
![]() |
提出日時 | 2021-11-10 09:38:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 79 ms / 5,000 ms |
コード長 | 2,020 bytes |
コンパイル時間 | 2,485 ms |
コンパイル使用メモリ | 77,788 KB |
実行使用メモリ | 52,428 KB |
最終ジャッジ日時 | 2024-11-20 18:03:51 |
合計ジャッジ時間 | 4,471 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
import java.util.*;import java.io.*;public class Main {public static void main(String[] args) throws Exception {Scanner sc = new Scanner();int[] ita = new int[4];for (int i = 0; i < 4; i++) {ita[i] = sc.nextInt();}int ans = Integer.MAX_VALUE;for (int i = 1; i <= 30; i++) {for (int j = i + 1; j <= 30; j++) {for (int k = j + 1; k <= 30; k++) {int sum = 0;int[] dp = new int[31];int[] piece = new int[]{i, j, k};for (int l = 0; l < 4; l++) {sum += dfw(ita[l], piece, dp);}ans = Math.min(ans, sum);}}}System.out.println(ans);}static int dfw(int size, int[] piece, int[] dp) {if (size < 0) {return 40;}if (size == 0) {return 0;}if (dp[size] == 0) {dp[size] = Integer.MAX_VALUE;for (int x : piece) {dp[size] = Math.min(dp[size], dfw(size - x, piece, dp) + 1);}}return dp[size];}}class Scanner {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer("");public Scanner() throws Exception {}public int nextInt() throws Exception {return Integer.parseInt(next());}public long nextLong() throws Exception {return Long.parseLong(next());}public double nextDouble() throws Exception {return Double.parseDouble(next());}public String nextLine() throws Exception {return br.readLine();}public String next() throws Exception {if (!st.hasMoreTokens()) {st = new StringTokenizer(br.readLine());}return st.nextToken();}}