結果

問題 No.37 遊園地のアトラクション
ユーザー htensai
提出日時 2019-12-07 10:38:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 156 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 3,120 ms
コンパイル使用メモリ 77,252 KB
実行使用メモリ 42,036 KB
最終ジャッジ日時 2024-10-10 13:36:24
合計ジャッジ時間 7,447 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int t;
    static int n;
    static int[] tArr;
    static int[] vArr;
    static int[][] dp;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		t = sc.nextInt();
		n = sc.nextInt();
		tArr = new int[n + 1];
		for (int i = 1; i <= n; i++) {
		    tArr[i] = sc.nextInt();
		}
		vArr = new int[n + 1];
		for (int i = 1; i <= n; i++) {
		    vArr[i] = sc.nextInt();
		}
		dp = new int[n + 1][t + 1];
		System.out.println(dfw(n, t));
   }
   
   static int dfw(int idx, int time) {
       if (idx == 0) {
           return 0;
       }
       if (dp[idx][time] != 0) {
           return dp[idx][time];
       }
       int value = vArr[idx];
       int total = 0;
       for (int i = 0; i * tArr[idx] <= time ; i++) {
           dp[idx][time] = Math.max(dp[idx][time], total + dfw(idx - 1, time - i * tArr[idx]));
           if (value <= 0) {
               break;
           }
           total += value;
           value /= 2;
       }
       return dp[idx][time];
   }
}

0