文件名称:Knapsack
介绍说明--下载内容来自于网络,使用问题请自行百度
算法设计与分析中背包问题。
首先将最优解矩阵的第一行和第一列均赋值为0;然后从上至下、从左至右依次计算m[i][j]的值,如果第i个物品
的重量大于j的值,即第i个物品不放入背包中,则将m[i][j]赋值为m[i-1][j],否则取第i个物品放入背包和不放入背
包所得价值的最大值;最后从后往前计算最优解向量的值,如果m[i][j]=m[i-1][j],则将x[i]赋值为0,否则将x[i]
赋值为1,并将j减去第i个物品的重量。-The knapsack problem algorithm design and analysis. First, the optimal solution in the first row and first column of the matrix are assigned 0 then from top to bottom, computing m [i] [j] values from left to right, if the weight is greater than the i-th item j values, i.e., the i-th item is not put into the backpack, then m [i] [j] assigned to m [i-1] [j], otherwise, it is the i-th item is not put into the resultant bags and backpacks the maximum value finally calculate the optimal solution from the previous value of the vector, if m [i] [j] = m [i-1] [j], then the x [i] values 0, otherwise x [i] value of 1, the i-th and j minus the weight of the article.
首先将最优解矩阵的第一行和第一列均赋值为0;然后从上至下、从左至右依次计算m[i][j]的值,如果第i个物品
的重量大于j的值,即第i个物品不放入背包中,则将m[i][j]赋值为m[i-1][j],否则取第i个物品放入背包和不放入背
包所得价值的最大值;最后从后往前计算最优解向量的值,如果m[i][j]=m[i-1][j],则将x[i]赋值为0,否则将x[i]
赋值为1,并将j减去第i个物品的重量。-The knapsack problem algorithm design and analysis. First, the optimal solution in the first row and first column of the matrix are assigned 0 then from top to bottom, computing m [i] [j] values from left to right, if the weight is greater than the i-th item j values, i.e., the i-th item is not put into the backpack, then m [i] [j] assigned to m [i-1] [j], otherwise, it is the i-th item is not put into the resultant bags and backpacks the maximum value finally calculate the optimal solution from the previous value of the vector, if m [i] [j] = m [i-1] [j], then the x [i] values 0, otherwise x [i] value of 1, the i-th and j minus the weight of the article.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
Knapsack.java
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.