結果

問題 No.2364 Knapsack Problem
ユーザー i_am_noobi_am_noob
提出日時 2023-06-30 21:28:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 3,000 ms
コード長 811 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 198,708 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 15:15:21
合計ジャッジ時間 2,926 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

int n,m,w,a[20],b[20];
bool dp[1<<15];

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m >> w; n+=m;
    for(int i=0; i<n-m; ++i) cin >> a[i];
    for(int i=0; i<n-m; ++i) cin >> b[i];
    for(int i=0; i<m; ++i) cin >> a[n-m+i],a[n-m+i]*=-1;
    for(int i=0; i<m; ++i) cin >> b[n-m+i],b[n-m+i]*=-1;
    dp[0]=1;
    int res=0;
    for(int s=0; s<(1<<n); ++s) if(dp[s]){
        int tot=0,val=0;
        for(int i=0; i<n; ++i) if(s>>i&1) tot+=a[i],val+=b[i];
        for(int i=0; i<n; ++i) if(!(s>>i&1)) if(tot+a[i]>=0&&tot+a[i]<=w) dp[s^(1<<i)]=1;
        res=max(res,val);
    }
    cout << res << "\n";
}
0