結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー |
![]() |
提出日時 | 2020-05-08 16:28:36 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 1,022 bytes |
コンパイル時間 | 2,286 ms |
コンパイル使用メモリ | 78,132 KB |
実行使用メモリ | 44,876 KB |
最終ジャッジ日時 | 2024-07-03 09:52:44 |
合計ジャッジ時間 | 7,134 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
import java.util.*; public class Main { static int[] xArr; static int[] yArr; static int[] cArr; static int[][][] dp; static int fee; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int goalX = sc.nextInt(); int goalY = sc.nextInt(); int n = sc.nextInt(); fee = sc.nextInt(); xArr = new int[n]; yArr = new int[n]; cArr = new int[n]; for (int i = 0; i < n; i++) { xArr[i] = sc.nextInt(); yArr[i] = sc.nextInt(); cArr[i] = sc.nextInt(); } dp = new int[n][goalX + 1][goalY + 1]; System.out.println(dfw(n - 1, goalX, goalY)); } static int dfw(int idx, int x, int y) { if (idx < 0) { return (x + y) * fee; } if (dp[idx][x][y] != 0) { return dp[idx][x][y]; } dp[idx][x][y] = dfw(idx - 1, x, y); if (xArr[idx] <= x && yArr[idx] <= y) { dp[idx][x][y] = Math.min(dp[idx][x][y], dfw(idx - 1, x - xArr[idx], y - yArr[idx]) + cArr[idx]); } return dp[idx][x][y]; } }