結果
問題 |
No.37 遊園地のアトラクション
|
ユーザー |
|
提出日時 | 2016-03-12 14:21:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,095 bytes |
コンパイル時間 | 518 ms |
コンパイル使用メモリ | 63,024 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-25 03:19:47 |
合計ジャッジ時間 | 4,491 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 WA * 3 RE * 17 |
ソースコード
#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; }