Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
142166 江婉儿 0/1背包问题 C++ 通过 100 1 MS 252 KB 260 2024-04-06 17:06:14

Tests(10/10):


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


测评信息: