結果

問題 No.2364 Knapsack Problem
ユーザー as277575as277575
提出日時 2023-06-30 22:02:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 3,000 ms
コード長 1,389 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 122,276 KB
実行使用メモリ 67,836 KB
最終ジャッジ日時 2023-09-21 16:02:26
合計ジャッジ時間 3,286 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 5 ms
4,828 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 13 ms
8,684 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 13 ms
10,152 KB
testcase_10 AC 5 ms
4,872 KB
testcase_11 AC 3 ms
4,500 KB
testcase_12 AC 134 ms
67,716 KB
testcase_13 AC 131 ms
67,660 KB
testcase_14 AC 131 ms
67,824 KB
testcase_15 AC 139 ms
67,704 KB
testcase_16 AC 132 ms
67,784 KB
testcase_17 AC 136 ms
67,664 KB
testcase_18 AC 130 ms
67,664 KB
testcase_19 AC 140 ms
67,836 KB
testcase_20 AC 139 ms
67,648 KB
testcase_21 AC 131 ms
67,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bit>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <set>
#include <string>

using namespace::std;

template <typename T>
void print(const T& v) {
 for (const auto& x : v) cout << x << " ";
 cout << endl;
}

int main() {
  ios::sync_with_stdio(false);
   long long n, m, w;
  cin >> n >> m >> w;
  vector< long long> dw(n + m);
  for ( long long i = 0ll; i < n; ++i) cin >> dw[i];
  vector< long long> dv(n + m);
  for ( long long i = 0ll; i < n; ++i) cin >> dv[i];
  for ( long long i = 0ll; i < m; ++i) { cin >> dw[n + i]; dw[n + i] = -dw[n + i]; }
  for ( long long i = 0ll; i < m; ++i) { cin >> dv[n + i]; dv[n + i] = -dv[n + i]; }
  
  vector<vector<long long>> d(1ll << (n + m), vector<long long>(w + 1ll, -1e18 - 7));
  d[0][0] = 0;
  long long r = -1e18 - 7;
  for ( long long s = 1ll; s < 1ll << (n + m); ++s)
    for ( long long i = 0ll; i < n + m; ++i)
      if (s & (1ll << i))
        for ( long long pw = 0ll; pw <= w; ++pw) {
           long long nw = pw + dw[i];
          if (0ll <= nw && nw <= w) {
            d[s][nw] = max(d[s][nw], d[s ^ (1ll << i)][pw] + dv[i]);   
            r = max(r, d[s][nw]);
          }
        }
  
  cout << r << endl;

  return 0;
}

0