From 73cea4d52ebde9e0c2c0de24e80b8783088b6e9e Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Fri, 25 Jul 2025 17:00:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=AE=97=E6=B3=95=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=9C=AA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=20DFS=20=E5=87=BD=E6=95=B0=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20DP=20=E5=87=BD=E6=95=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BE=93=E5=85=A5=E8=BE=93=E5=87=BA=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/7/25/T639173.cpp | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/7/25/T639173.cpp b/src/7/25/T639173.cpp index c66fcee..cc01c31 100644 --- a/src/7/25/T639173.cpp +++ b/src/7/25/T639173.cpp @@ -1,42 +1,34 @@ -/* -2 10 7 11 -2 10 -6 1 - -n=2, W=10, B=7, X=11 -c[1]=2,c[2]=10 -cost[1]=6,cost[2]=1 - -*/ - #include #include #include #include +#include +#include #include using ll = int64_t; -#define il static inline -ll n,w,b,x,ans=0; +ll n,w,b,x; std::vector c,cost; +constexpr ll inf = std::numeric_limits::min(); -il void dfs(ll nn,ll nw,ll nb,ll nc){ - if(nn>n){ - ans=std::max(ans,nc); - return; +static inline ll dp(ll i,ll j){ + if(i==0){ + if(j==0)return w; + else return inf; } - for(ll i=0;i<=c[nn];i++){ - if(nw> vdp(n+1,std::vector(10000+1,inf)); + if(vdp[i][j]!=inf)return vdp[i][j]; + for(ll k=0;k<=c[i];k++){ + if(j-k<0||dp(i-1,j-k)<0)continue; + vdp[i][j]=std::max(vdp[i][j],std::min(dp(i-1, j-k)+x,w+(j-k)*b)-cost[i]*k); } + return vdp[i][j]; } int main(){ std::iostream::sync_with_stdio(false); std::cin.tie(nullptr); - std::cout.tie(nullptr); - std::cin>>n>>w>>b>>x; c.resize(n+1); cost.resize(n+1); @@ -46,6 +38,11 @@ int main(){ for(ll i=1;i<=n;i++){ std::cin>>cost[i]; } - dfs(1, w, b, 0); - std::cout<=0;i--){ + if(dp(n, i)>=0){ + std::cout<