結果

問題 No.37 遊園地のアトラクション
ユーザー d2verbd2verb
提出日時 2016-02-16 19:32:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 69,140 KB
実行使用メモリ 8,488 KB
最終ジャッジ日時 2023-10-22 06:00:49
合計ジャッジ時間 2,238 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int t, n;
vector<int> c, v;
vector< vector<int> > dp;

/* _n番目までのアトラクションを使って, 時間制限_t以内に得られる最大満足度 */
int solve(int _n, int _t) {
  if (_n < 0) return 0;
  if (dp[_n][_t] != -1) return dp[_n][_t];

  int ret = -1;
  if (_t - c[_n] > 0) ret = max(ret, solve(_n - 1, _t - c[_n]) + v[_n]);
  ret = max(ret, solve(_n - 1, _t));
  return dp[_n][_t] = ret;
}

int main(void) {
  cin >> t >> n;
  
  c.assign(n, 0);
  v.assign(n, 0);
  
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n; i++) cin >> v[i];

  /* 新しいアトラクションの生成 */
  for (int i = 0; i < n; i++) {
    int _v = v[i];
    while (true) {
      _v = _v / 2;
      if (_v == 0) break;
      v.push_back(_v);
      c.push_back(c[i]);
    }
  }

  dp.assign(c.size(), vector<int>(t + 1, -1));
  cout << solve(c.size() - 1, t) << endl;

  return 0;
}
0