Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
142008 沈梓珺 0/1背包问题 C++ 运行出错 0 0 MS 88 KB 375 2024-04-06 15:52:22

Tests(0/10):


#include<bits/stdc++.h> using namespace std; int n,m; int f[11000][11000],w[110000],c[110000]; 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=0;j<=m;j++){ if(j<w[i]){ f[i][j]=f[i-1][j]; } else{ f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+c[i]); } } } cout<<f[n][m]; return 0; }


测评信息: