結果

問題 No.2364 Knapsack Problem
ユーザー momoyuumomoyuu
提出日時 2023-10-25 15:25:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,301 bytes
コンパイル時間 3,171 ms
コンパイル使用メモリ 255,120 KB
実行使用メモリ 584,552 KB
最終ジャッジ日時 2023-10-25 15:25:52
合計ジャッジ時間 27,590 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 13 ms
9,804 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 23 ms
12,180 KB
testcase_05 AC 51 ms
25,644 KB
testcase_06 AC 24 ms
12,180 KB
testcase_07 AC 922 ms
266,676 KB
testcase_08 AC 4 ms
4,816 KB
testcase_09 WA -
testcase_10 AC 422 ms
134,940 KB
testcase_11 AC 50 ms
20,852 KB
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
   
    int n,m,w;
    cin>>n>>m>>w;
    vector<ll> a(n),b(n),c(m),d(m);
    for(int i = 0;i<n;i++) cin>>a[i];
    for(int i = 0;i<n;i++) cin>>b[i];
    for(int i = 0;i<m;i++) cin>>c[i];
    for(int i = 0;i<m;i++) cin>>d[i];

    vector<vector<vector<ll>>> dp(1<<n,vector<vector<ll>>(1<<m,vector<ll>(w+1+4000,-1e18)));
    dp[0][0][4000] = 0;

    ll ans = -1e18;
    for(int i = 0;i<1<<n;i++){
        for(int j = 0;j<1<<m;j++){
            for(int k = 0;k<=w+4000;k++){
                ans = max(ans,dp[i][j][k]);
                for(int l = 0;l<n;l++){
                    if(i>>l&1) continue;
                    int ni = i | (1<<l);
                    int nxt = k + a[l];
                    if(nxt>w+4000) continue;
                    dp[ni][j][nxt] = max(dp[ni][j][nxt],dp[i][j][k]+b[l]);
                }
                for(int l = 0;l<m;l++){
                    if(j>>l&1) continue;
                    int ni = j | (1<<l);
                    int nxt = k - c[l];
                    if(nxt<0) continue;
                    dp[i][ni][nxt] = max(dp[i][ni][nxt],dp[i][j][k]-d[l]);
                }
            }
        }
    }
    cout<<ans<<endl;
}
0