题目描述
01背包
样例
input:
4 5
1 2
2 4
3 4
4 5
output:
8
算法1
时间复杂度
$O(n*V)$
C++ 代码
int n,V;
int w[maxn], v[maxn], dp[maxn][maxn];
void solve(){
read(n, V);
rep(i, 1, n) read(v[i], w[i]);
rep(i, 1, n) rep(j, 1, V){
if(j < v[i]) dp[i][j] = dp[i-1][j];
else dp[i][j] = max(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
}
cout << dp[n][V] << endl;
}
请问,我的代码怎么没有高亮,萌新一个~