题解:
woc竟然有个小地方没看出错来,WA了半天
DP一下
注意爆long long
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long Lint; int n; Lint m; int ans=0x7fffffff; Lint f[130][300000]={0}; int k[130],c[130],sumcost=0; int main(){ scanf("%d%lld",&n,&m); for(int i=1;i<=n;++i)scanf("%d",&k[i]); for(int i=1;i<=n;++i)scanf("%d",&c[i]); for(int i=1;i<=n;++i)sumcost=sumcost+k[i]*c[i]; f[1][0]=1; for(int i=2;i<=k[1];++i)f[1][i*c[1]]=i; for(int i=1;i<n;++i){ for(int j=0;j<=sumcost;++j)f[i+1][j]=max(f[i+1][j],f[i][j]); for(int a=2;a<=k[i+1];++a){ for(int j=0;j<=sumcost;++j){ f[i+1][j+a*c[i+1]]=min(m,max(f[i+1][j+a*c[i+1]],f[i][j]*a)); } } } // for(int i=0;i<=sumcost;++i)cout<<f[1][i]<<‘ ‘; // cout<<endl; for(int j=0;j<=sumcost;++j){ if(f[n][j]>=m)ans=min(ans,j); } cout<<ans<<endl; return 0; }