package niukewang_jianzhiOffer;
/**
* Created by zhangwenjie05 on 16/9/10.
*/
public class PakageQuestion {
//物体的重
static int weight[] = {2, 3, 1, 4, 6, 5};
//物体的价值
static int value[] = {5, 6, 5, 1, 19, 7};
// maxValue[i][j]保存容量为I的背包从j个物体中选择最大价值的物体放入后最大的价值和
static int maxValue[][] = new int[11][6];
public static void main(String args[]) {
// 初始化 -1表示没有存储值
for (int i = 0; i < 11; i++)
for (int j = 0; j < 6; j++) {
maxValue[i][j] = -1;
}
//包容量10,有5个物体的最大价值
int r = maxValue(10, 5);
System.out.println("最大价值:"+r);
int total = 10;
//打印输出选取了那几个物体
for (int
背包问题,http://www.cnblogs.com/sdjl/articles/1274312.html 这篇文章介绍很详细,参照它的思路写了0/1背包问题代码。package niukewang_jianzhiOffer;/** * Created by zhangwenjie05 on 16/9/10. */public class PakageQuestion { //