結果

問題 No.37 遊園地のアトラクション
ユーザー tsukiotsukio
提出日時 2016-03-12 14:21:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,095 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 63,248 KB
実行使用メモリ 5,044 KB
最終ジャッジ日時 2023-10-25 08:06:26
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 2 ms
4,348 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 6 ms
4,348 KB
testcase_13 RE -
testcase_14 AC 5 ms
4,580 KB
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 2 ms
4,348 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 RE -
testcase_28 AC 2 ms
4,348 KB
testcase_29 RE -
testcase_30 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int memo[150][10010] = {};

int CalcMaxValue(vector<pair<int, int>>& attractions, int index, int term_index, int t) {
	if (t == 0) return 0;
	if (index >= term_index) return 0;

	if (memo[index][t] == 0) {
		int cost = attractions[index].first;
		int value = attractions[index].second;
		if (t - cost >= 0) {
			attractions[term_index] = pair<int, int>(cost, value / 2);
			int ret = value + CalcMaxValue(attractions, index + 1, term_index + 1, t - cost);
			memo[index][t] = max(ret, CalcMaxValue(attractions, index + 1, term_index, t));
		}
		else {
			memo[index][t] = CalcMaxValue(attractions, index + 1, term_index, t);
		}
	}

	return memo[index][t];
}

int main() {
	int t, n;
	cin >> t >> n;

	int costs[20];
	for (int i = 0; i < n; i++) {
		cin >> costs[i];
	}

	vector<pair<int, int>> attractions(150);
	for (int i = 0; i < n; i++) {
		int value;
		cin >> value;
		attractions[i] = pair<int, int>(costs[i], value);
	}

	cout << CalcMaxValue(attractions, 0, n, t) << endl;

	return 0;
}
0