結果
| 問題 |
No.2232 Miser's Gift
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-03 21:46:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 255 ms / 2,000 ms |
| コード長 | 1,887 bytes |
| コンパイル時間 | 2,077 ms |
| コンパイル使用メモリ | 196,396 KB |
| 最終ジャッジ日時 | 2025-02-11 02:15:01 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 55 |
ソースコード
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
#define debug1(a) { cerr<<#a<<":"<<a<<endl; }
#define debug2(a,b) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl; }
#define debug3(a,b,c) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl; }
#define debug4(a,b,c,d) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<endl; }
// clang-format on
vector<pll> goods;
ll W;
ll dp(ll i, ll w) {
static bool done[102][100005];
static ll memo[102][100005];
if (i < 0) return 0;
if (done[i][w]) return memo[i][w];
done[i][w] = true;
ll N = goods.size();
ll wi = goods[i].first;
ll vi = goods[i].second;
ll ans = dp(i - 1, w);
if (w - wi >= 0) {
ans = max(ans, vi + dp(i - 1, w - wi));
}
if (w > 0) {
ans = max(ans, dp(i, w - 1));
}
return memo[i][w] = ans;
}
int main() {
ioinit();
ll N;
cin >> N >> W;
for (ll i = 0; i < N; i++) {
ll w, v;
cin >> w >> v;
goods.push_back({w, v});
}
ll initans = dp(N - 1, W);
for (ll x = 1; x <= W; x++) {
ll cur = dp(N - 1, W - x);
ll v = initans - cur + 1;
print(v);
}
return 0;
}