我...比较弱 暂时只能打出二进制优化 过段时间再来刚
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; #define ll long long #define rg register #define Max(x,y) (x)>(y)?(x):(y) #define Min(x,y) (x)>(y)?(y):(x) const int N=200+5,M=200000+5,inf=0x3f3f3f3f,P=19650827; int n,m,ans=0,cnt=0,f[M],w[M],v[M]; template <class t>void rd(t &x){ x=0;int w=0;char ch=0; while(!isdigit(ch)) w|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=w?-x:x; } int main(){ // freopen("in.txt","r",stdin); rd(n),rd(m); for(int i=1,a,b,c;i<=n;++i){ rd(a),rd(b),rd(c); for(int j=1;j<=c;j<<=1) w[++cnt]=j*a,v[cnt]=j*b,c-=j; if(c) w[++cnt]=c*a,v[cnt]=c*b; } for(int i=1;i<=cnt;++i){ for(int j=m;j>=v[i];--j) f[j]=Max(f[j],f[j-v[i]]+w[i]); } printf("%d",f[m]); return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; #define ll long long #define rg register #define Max(x,y) (x)>(y)?(x):(y) #define Min(x,y) (x)>(y)?(y):(x) const int N=200+5,M=200000+5,inf=0x3f3f3f3f,P=19650827; int n,w,ans=0,a[N],b[N],c[N],f[M]; template <class t>void rd(t &x){ x=0;int w=0;char ch=0; while(!isdigit(ch)) w|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=w?-x:x; } int main(){ // freopen("in.txt","r",stdin); rd(n),rd(w); for(int i=1;i<=n;++i){ rd(a[i]),rd(b[i]),rd(c[i]); for(int v=w;v>=b[i];--v){ for(int j=1;j<=c[i];++j) if(v>=b[i]*j) f[v]=max(f[v],f[v-b[i]*j]+a[i]*j); ans=Max(ans,f[v]); } } printf("%d",ans); return 0; }