結果

問題 No.2364 Knapsack Problem
ユーザー cho435cho435
提出日時 2023-06-30 21:40:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 3,000 ms
コード長 752 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 206,676 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 15:33:55
合計ジャッジ時間 3,028 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)

int n,m,w;
vector<ll> a(7),b(7),c(7),d(7);
set<int> st;
ll dfs(int ct,int nw,ll nv){
	ll rt=nv;
	rep(i,n){
		if(!((ct>>i)&1)){
			if(nw+a.at(i)>w) continue;
			int nx=(ct|(1<<i));
			if(st.count(nx)) continue;
			st.insert(nx);
			rt=max(rt,dfs(nx,nw+a.at(i),nv+b.at(i)));
		}
	}
	rep(i,m){
		if(!((ct>>(i+n))&1)){
			if(nw-c.at(i)<0) continue;
			int nx=(ct|(1<<(i+n)));
			if(st.count(nx)) continue;
			st.insert(nx);
			rt=max(rt,dfs(nx,nw-c.at(i),nv-d.at(i)));
		}
	}
	return rt;
}

int main(){
	cin>>n>>m>>w;
	rep(i,n) cin>>a.at(i);
	rep(i,n) cin>>b.at(i);
	rep(i,m) cin>>c.at(i);
	rep(i,m) cin>>d.at(i);
	cout<<dfs(0,0,0)<<endl;
}
0