Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
49052 hanxizhe 完全背包问题 C++ 通过 1 MS 248 KB 339 2024-06-16 16:22:44

Tests(1/1):


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


测评信息: