解题思路:
注意事项:
参考代码:
#include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <cctype> #include <cstring> #include <string> #include <stack> #include <algorithm> #include <functional> using namespace std; const int maxv=201; const int maxw=5001; int w[maxw], v[maxv], dp[maxv][maxw]; int main() { int n, m; memset(dp, 0, sizeof(dp)); scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) { scanf("%d%d", &w[i], &v[i]); } for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { if(j >= w[i]) dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]); else dp[i][j] = dp[i-1][j]; } } printf("%d\n", dp[n][m]); return 0; }
0.0分
2 人评分
C语言训练-求PI* (C语言代码)浏览:614 |
WU-蓝桥杯算法提高VIP-Quadratic Equation (C++代码)浏览:1752 |
Wu-求圆的面积 (C++代码)浏览:1891 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:472 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:565 |
【计算两点间的距离】 (C语言代码)浏览:1493 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:607 |
循环入门练习5 (C语言代码)浏览:839 |
C语言训练-字符串正反连接 (C语言代码)浏览:632 |
【出圈】 (C++代码)简单循环浏览:639 |