結果
問題 | No.2026 Yet Another Knapsack Problem |
ユーザー |
|
提出日時 | 2023-05-11 22:26:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 339 ms / 10,000 ms |
コード長 | 1,106 bytes |
コンパイル時間 | 1,919 ms |
コンパイル使用メモリ | 195,916 KB |
最終ジャッジ日時 | 2025-02-12 21:24:24 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#include<bits/stdc++.h>#define int long long#define rep(i,a,b) for(int i=(a);i<=(b);i++)#define per(i,a,b) for(int i=(a);i>=(b);i--)#define fi first#define se second#define eb emplace_back#define popc __builtin_popcountusing namespace std;typedef long long ll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<pii> vp;typedef unsigned long long ull;typedef long double ld;int read() {int x=0,w=1; char c=getchar();while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}return x*w;}const int N=2509,inf=0x3f3f3f3f3f3f3f3f;int n,c[N],v[N*12],f[N][N],tot;typedef tuple<int,int,int> tiii;tiii p[N*12];signed main() {n=read();rep(i,1,n) c[i]=read(), v[i]=read();rep(i,1,n) rep(h,0,11) if(c[i]) {int x=min(c[i],1ll<<h); c[i]-=x;p[++tot]=tiii(i,x,v[i]);}rep(j,0,n) rep(k,0,n) f[j][k]=(j>0)*-inf;per(i,tot,1) {auto [w,c,v]=p[i];per(j,n/w,c) {per(k,n,w*c) {f[j][k]=max(f[j][k],f[j-c][k-w*c]+v*c);}}}rep(i,1,n) printf("%lld\n",f[i][n]);return 0;}