結果

問題 No.2364 Knapsack Problem
ユーザー iwaiwaiwaispiwaiwaiwaisp
提出日時 2023-06-30 21:54:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,322 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 171,952 KB
実行使用メモリ 7,904 KB
最終ジャッジ日時 2023-09-21 15:50:04
合計ジャッジ時間 2,927 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,612 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 4 ms
5,012 KB
testcase_05 AC 4 ms
5,404 KB
testcase_06 AC 4 ms
4,828 KB
testcase_07 AC 7 ms
7,404 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 6 ms
6,788 KB
testcase_11 AC 4 ms
5,216 KB
testcase_12 AC 8 ms
7,796 KB
testcase_13 AC 7 ms
7,808 KB
testcase_14 WA -
testcase_15 AC 7 ms
7,852 KB
testcase_16 AC 7 ms
7,844 KB
testcase_17 AC 7 ms
7,760 KB
testcase_18 AC 7 ms
7,852 KB
testcase_19 AC 7 ms
7,804 KB
testcase_20 AC 7 ms
7,796 KB
testcase_21 AC 7 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
//#include <atcoder/all>
using namespace std;

#define reps(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define rep(i, n) reps(i, 0, n)

#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による

#define ll long long
#define vmax(x) *max_element(x.begin(), x.end())
#define vmin(x) *min_element(x.begin(), x.end())


#define F first
#define S second

#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;
#define coutALL2d(vv) for(const auto& v : vv){for(const auto& e : v){cout << e << " ";}cout << endl;}
#define cout2(x,y) cout << x << " " << y << endl;
#define cout3(x,y,z) cout << x << " " << y << " " << z << endl;

#define vi vector<int>
#define vvi vector<vector<int> >
#define vll vector<long long>
#define vvll vector<vector<long long> >


int main(){
    int n,m,w;
    cin >> n >> m >> w;
    vi a(n);
    vi b(n);
    vi c(m);
    vi d(m);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,m) cin >> c[i];
    rep(i,m) cin >> d[i];
    #define W 5000
    vector<vector<vector<int> > > dp(n+m+1, vvi(n+m+1,vi(W)));

    reps(i,1,n+m+1){
        reps(j,1,i+1){
            reps(k,1,W){
                if(i <= n){
                    if(k-a[i-1] >= 0){
                        dp[i][j][k] = max({dp[i-1][j][k], dp[i-1][j-1][k-a[i-1]]+b[i-1]});
                    }
                    else{
                        dp[i][j][k] = dp[i-1][j][k];
                    }
                }
                else{
                    if(k+c[i-n-1] < W){
                        dp[i][j][k] = max({dp[i-1][j][k], dp[i-1][j-1][k+c[i-n-1]]-d[i-n-1]});
                    }
                    else{
                        dp[i][j][k] = dp[i-1][j][k];
                    }
                }
            }
        }
        //coutALL2d(dp[i]);
        //cout << endl;
    }
    int res = 0;
    reps(j,1,n+m+1){
        reps(k,1,W){
            if(k <= w){
                res = max({res,dp[n+m][j][k]});
            }
        }
    }
    cout << res << endl;
}





0