提出詳細


ソースコード

import java.util.Scanner;

public class Main_DP {
	int n, budget;
	int[] budgets;
	int[] sizes;
	Set[][] dp;

	Main_DP() {
		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		budget = sc.nextInt();

		dp = new Set[n+1][budget+1];

		budgets = new int[n+1];
		sizes = new int[n+1];

		for (int i = 1; i <= n; i++) {
			int price = sc.nextInt();
			int size = sc.nextInt();
			budgets[i] = price;
			sizes[i] = size;
		}
	}

	Set getResult() {
		return calc(n, budget);
	}

	static int count;

	Set calc(int num, int budget) {
		if(dp[num][budget] != null)
			return dp[num][budget];

		if (num == 0) {
			return new Set(this.budget - budget, 0);
		} else if (budget < budgets[num]) {
			return dp[num][budget] = new Set(calc(num-1, budget));
		} else {
			Set set1 = new Set(calc(num-1, budget));
			Set set2 = new Set(calc(num-1, budget - budgets[num]));
			set2.size += sizes[num];

			dp[num][budget] = set1.size > set2.size ? set1 : set2;
			return dp[num][budget];
		}
	}

	public static void main(String[] args) {
		Set result = new Main_DP().getResult();
		System.out.println(result.price + " " + result.size);
	}

	class Set {
		public Set(Set set) {
			this.price = set.price;
			this.size = set.size;

		}

		public Set(int price, int size) {
			this.price = price;
			this.size = size;
		}

		long price;
		long size;
	}
}

提出情報

提出時間 2019-11-27 04:57:59
問題 J - 質より量 (large)
ユーザ名 teracoder
状態 不正解
正解率 20/21
提出出力結果

テストケース情報

# 状態 詳細情報
テストケース 1 正解 詳細を見る
テストケース 2 正解 詳細を見る
テストケース 3 正解 詳細を見る
テストケース 4 正解 詳細を見る
テストケース 5 正解 詳細を見る
テストケース 6 正解 詳細を見る
テストケース 7 正解 詳細を見る
テストケース 8 正解 詳細を見る
テストケース 9 正解 詳細を見る
テストケース 10 正解 詳細を見る
テストケース 11 正解 詳細を見る
テストケース 12 正解 詳細を見る
テストケース 13 正解 詳細を見る
テストケース 14 正解 詳細を見る
テストケース 15 正解 詳細を見る
テストケース 16 正解 詳細を見る
テストケース 17 正解 詳細を見る
テストケース 18 正解 詳細を見る
テストケース 19 正解 詳細を見る
テストケース 20 正解 詳細を見る
テストケース 21 正解 詳細を見る
テストケース 22 正解 詳細を見る
テストケース 23 正解 詳細を見る
テストケース 24 正解 詳細を見る
テストケース 25 正解 詳細を見る
テストケース 26 正解 詳細を見る
テストケース 27 正解 詳細を見る
テストケース 28 正解 詳細を見る
テストケース 29 正解 詳細を見る
テストケース 30 正解 詳細を見る
テストケース 31 正解 詳細を見る
テストケース 32 正解 詳細を見る
テストケース 33 正解 詳細を見る
テストケース 34 正解 詳細を見る
テストケース 35 正解 詳細を見る
テストケース 36 正解 詳細を見る
テストケース 37 正解 詳細を見る
テストケース 38 正解 詳細を見る
テストケース 39 正解 詳細を見る
テストケース 40 正解 詳細を見る
テストケース 41 正解 詳細を見る
テストケース 42 正解 詳細を見る
テストケース 43 正解 詳細を見る
テストケース 44 正解 詳細を見る
テストケース 45 正解 詳細を見る
テストケース 46 正解 詳細を見る
テストケース 47 正解 詳細を見る
テストケース 48 正解 詳細を見る
テストケース 49 正解 詳細を見る
テストケース 50 正解 詳細を見る