結果
問題 | No.2364 Knapsack Problem |
ユーザー |
|
提出日時 | 2023-06-30 21:28:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 3,000 ms |
コード長 | 811 bytes |
コンパイル時間 | 2,101 ms |
コンパイル使用メモリ | 191,636 KB |
最終ジャッジ日時 | 2025-02-15 03:30:43 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#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";}