結果
| 問題 |
No.158 奇妙なお使い
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-05-15 13:45:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 854 ms / 5,000 ms |
| コード長 | 1,319 bytes |
| コンパイル時間 | 1,987 ms |
| コンパイル使用メモリ | 86,272 KB |
| 実行使用メモリ | 100,172 KB |
| 最終ジャッジ日時 | 2025-01-01 18:09:55 |
| 合計ジャッジ時間 | 9,000 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
package no158;
import java.util.Arrays;
import java.util.Scanner;
public class Main implements Runnable {
public static void main(String[] args) {
new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
}
int a1000,a100,a1,b1000,b100,b1,db,c1000,c100,c1,dc;
int[][][] dp = new int[11][101][10001];
public void run() {
Scanner sc = new Scanner(System.in);
a1000 = sc.nextInt();
a100 = sc.nextInt();
a1 = sc.nextInt();
db = sc.nextInt();
b1000 = sc.nextInt();
b100 = sc.nextInt();
b1 = sc.nextInt();
dc = sc.nextInt();
c1000 = sc.nextInt();
c100 = sc.nextInt();
c1 = sc.nextInt();
for(int i=0;i<=10;i++) {
for(int j=0;j<=100;j++) {
Arrays.fill(dp[i][j], -1);
}
}
System.out.println(dfs(a1000,a100,a1));
sc.close();
}
public int dfs(int a,int b,int c) {
if (a < 0 || b < 0 || c < 0) {
return 0; //苦し紛れ
}
if (dp[a][b][c] >= 0) {
return dp[a][b][c];
}
int max = 0;
for(int i=0;i<=a;i++) {
for(int j=0;j<=b;j++) {
int bx = db - i * 1000 - j * 100;
if (bx >= 0 && bx <= c) {
max = Math.max(max, dfs(a-i+b1000, b-j+b100, c-bx+b1) + 1);
}
int cx = dc - i * 1000 - j * 100;
if (cx >= 0 && cx <= c) {
max = Math.max(max, dfs(a-i+c1000, b-j+c100, c-cx+c1) + 1);
}
}
}
return dp[a][b][c] = max;
}
}
ぴろず