文章
72
粉丝
142
获赞
5
访问
57.6k
#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int w[maxn];//价格
int v[maxn];//分数
int dp[maxn][maxn];
int main() {
int c, n;
cin >> c >> n;
for (int i = 1; i <= n;i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n;i++) {//初始化列
dp[i][0] = 0;
}
for (int i = 0; i <= c;i++) {//初始化行
dp[0][i] = 0;
}
for (int i = 1; i <= n;i++) {
for (int j = 1; j <= c; j++) {
if (j >= w[i]) {
dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
&nb...
登录后发布评论
数组开小了