結果
| 問題 | No.37 遊園地のアトラクション | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-03-12 18:06:49 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 5,000 ms | 
| コード長 | 1,023 bytes | 
| コンパイル時間 | 606 ms | 
| コンパイル使用メモリ | 63,768 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-10 13:11:59 | 
| 合計ジャッジ時間 | 1,626 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 27 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int memo[150][10010] = {};
int CalcMaxValue(const vector<pair<int, int>>& attractions, int index, int t) {
	if (t == 0) return 0;
	if (index >= attractions.size()) return 0;
	if (memo[index][t] == 0) {
		int cost = attractions[index].first;
		int value = attractions[index].second;
		if (t - cost >= 0) {
			memo[index][t] = max(
				value + CalcMaxValue(attractions, index + 1, t - cost),
				CalcMaxValue(attractions, index + 1, t));
		}
		else {
			memo[index][t] = CalcMaxValue(attractions, index + 1, 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;
	for (int i = 0; i < n; i++) {
		int value;
		cin >> value;
		while (value > 0) {
			attractions.push_back(pair<int, int>(costs[i], value));
			value /= 2;
		}
	}
	cout << CalcMaxValue(attractions, 0, t) << endl;
	
	return 0;
}
            
            
            
        