Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
49049 hanxizhe 01背包问题 C++ 通过 0 MS 248 KB 332 2024-06-16 16:01:46

Tests(1/1):


#include<bits/stdc++.h> using namespace std; int m,n; int w[35],c[35],f[35]; void z(int cost,int w){ for(int v = m;v>=w;v--){ f[v] = max(f[v],f[v-w]+cost); } } int main(){ cin>>m>>n; for(int i = 1;i<=n;i++){ cin>>w[i]>>c[i]; } for(int i = 1;i<=n;i++){ z(c[i],w[i]); } cout<<f[m]<<endl; return 0; }


测评信息: