Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
3492 liumingxuan 最大价值 C++ 通过 0 MS 264 KB 450 2023-01-08 15:56:44

Tests(1/1):


#include<bits/stdc++.h> using namespace std; int c[55],v[55]; int dp[55][605]; int main(){ int n,m; cin>>m>>n; for(int i=1;i<=n;i++)cin>>c[i]>>v[i]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(j>=c[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-c[i]]+v[i]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][m]; return 0; } /* #include<cstdio> freopen("文件名.in","r",stdin); freopen("文件名.out","w",stdout); */


测评信息: