結果

問題 No.2364 Knapsack Problem
ユーザー airths
提出日時 2023-06-30 22:09:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,134 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 132,036 KB
最終ジャッジ日時 2025-02-15 03:59:09
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

/*
*
* ^v^
*
*/
#include <iostream>
#include <numeric>
#include <set>
#include <iomanip>
#include <chrono>
#include <queue>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <algorithm>
#include <array>
#include <random>
using namespace std;
using ll = long long int;
using ld = long double;
#define iamtefu ios_base::sync_with_stdio(false); cin.tie(0);
#define fl(i,a,n) for (ll i(a); i<n; i++)
#define rfl(i,a,n) for (ll i(n-1); i>=a; i--)
#define ty int _; for(cin>>_; _--;)
#define print(a) for(auto ele:a){cout<<ele<<" ";}cout<<'\n';
ll gcd(ll a, ll b){
if (b==0){
return a;
}
return gcd(b, a%b);
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll pw(ll a, ll b, ll m){
ll res=1;
a%=m;
while (b){
if (b&1){
res=(res*a)%m;
}
a=(a*a)%m;
b/=2;
}
return res;
}
void scn(){
ll n, m, w; cin>>n>>m>>w;
vector <ll> a(n), b(n), c(m), d(m);
fl(i,0,n){
cin>>a[i];
}
fl(i,0,n){
cin>>b[i];
}
fl(i,0,m){
cin>>c[i];
}
fl(i,0,m){
cin>>d[i];
}
ll ans = 0;
vector <vector <vector <ll>>> dp(n+1, vector <vector <ll>>(m+1, vector <ll>(w+1, -1)));
auto rec=[&](auto rec, ll i, ll j, ll cw){
if (cw<0 || cw>w){
return -(ll)1e18;
}
if (i==n && j==m){
return 0ll;
}
// cout<<i<<" "<<cw<<" "<<j<<"\n";
if (dp[i][j][cw]!=-1){
return dp[i][j][cw];
}
ll an = -1e18;
fl(l,i,n){
an = max(an, b[l]+rec(rec, l+1, j, cw+a[l]));
}
fl(k,j,m){
an = max(an, rec(rec, i, k+1, cw-c[k])-d[k]);
}
dp[i][j][cw]=an;
return max(0ll,an);
};
ans = rec(rec, 0, 0, 0);
// for (auto x:dp){
// for (auto y:x){
// print(y)
// }
// }
cout<<ans<<'\n';
// not necessarily distinct
// right down
}
int main(){
iamtefu;
#if defined(airths)
auto t1=chrono::high_resolution_clock::now();
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// ty
{
scn();
}
#if defined(airths)
auto t2=chrono::high_resolution_clock::now();
ld ti=chrono::duration_cast<chrono::nanoseconds>(t2-t1).count();
ti*=1e-6;
cerr<<"Time: "<<setprecision(12)<<ti;
cerr<<"ms\n";
#endif
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0