結果

問題 No.37 遊園地のアトラクション
ユーザー k
提出日時 2021-02-19 21:27:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 194,412 KB
最終ジャッジ日時 2025-01-18 23:09:04
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int dp[10000+1][15];

int dfs(int t, int p, const vector<int> &c, const vector<int> &v) {
  if (p == c.size())
    return 0;

  int &ret = dp[t][p];
  if (ret >= 0)
    return ret;
  
  ret = dfs(t, p+1, c, v);
  int w = v[p];
  int u = 0;
  while (w && t >= c[p]) {
    u += w;
    ret = max(ret, u + dfs(t - c[p], p+1, c, v));
    w /= 2;
    t -= c[p];
  }

  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int t, n;
  cin >> t >> n;
  vector<int> c(n), v(n);
  for (int i = 0; i < n; i++)
    cin >> c[i];
  for (int i = 0; i < n; i++)
    cin >> v[i];

  memset(dp, -1, sizeof(dp));
  cout << dfs(t, 0, c, v) << endl;
  
  return 0;
}
0