问题 4167 --完全背包问题(完善程序)

4167: 完全背包问题(完善程序)★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 103  解决: 86
[提交][状态][命题人:]

题目描述

容量为10的背包,有5种物品,每种物品数量无限,其重量分别为5,4,3,2,1,其价值分别为1,2,3,4,5。设计算法,实现背包内物品价值最大。代码如下(输出50):


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
 	int total_weight = 10;
 	int w[6] = {0,5,4,3,2,1};
  	int v[6] = {0,1,2,3,4,5};
  	int dp[11] = {___(1)______};
  	for(int i=1;i<=____(2)_____;i++)   
  	  for(int j = w[i];j<=_____(3)______;j++)
  	    dp[j] =  ______(4)________;
    cout<< dp[_____(5)______] <<endl;  
    return 0;
}


输入

输出

提示

来源

[提交][状态]