文件名称:PackageProblem
- 所属分类:
- 其它资源
- 资源属性:
- [Windows] [Visual C] [源码]
- 上传时间:
- 2008-10-13
- 文件大小:
- 9.08kb
- 下载次数:
- 0次
- 提 供 者:
- 李**
- 相关连接:
- 无
- 下载说明:
- 别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容均来自于网络,请自行研究使用
实现背包问题
package problem
1. 问题描述
假设有一个能装入总体积为T的背包和n件体积分别为w1 , w2 , … , wn 的物品,能否从n件物品中挑选若干件恰好装满背包,即使w1 +w2 + … + wn=T,要求找出所有满足上述条件的解。例如:当T=10,各件物品的体积{1,8,4,3,5,2}时,可找到下列4组解: (1,4,3,2)、(1,4,5)、(8,2)、(3,5,2)。
2. 基本要求
读入T、n、w1 , w2 , … , wn
3.提示:
可利用递归方法:若选中w1 则问题变成在w2 , … , wn 中挑选若干件使得其重量之和为T- w1 ,若不选中w1,则问题变成在w2 , … , wn 中挑选若干件使得其重量之和为T 。依次类推。
也可利用回溯法的设计思想来解决背包问题。首先将物品排成一列,然后顺序选取物品装入背包,假设已选取了前i 件物品之后背包还没有装满,则继续选取第i+1件物品,若该件物品“太大”不能装入,则弃之而继续选取下一件,直至背包装满为止。但如果在剩余的物品中找不到合适的物品以填满背包,则说明“刚刚”装入背包的那件物品“不合适”,应将它取出“弃之一边”,继续再从“它之后”的物品中选取,如此重复,,直至求得满足条件的解,或者无解。
注:没压缩密码-knapsack problem achieve a package problem. Problem descr iption one would assume that the total volume of loaded backpack and T n size pieces of w1, w2, ..., wn items Can n items from the selected pieces were just filled with backpacks, even w1 w2 ... wn = T, asked to identify all of the above conditions are met solution. For example : when T = 10, the volume of items (1,8,4,3,5,2), may find the following four solutions : (1,4,3,2), (1,4,5), (8,2), (3,5,2). 2. Basic requirements read T, n, w1, w2, ..., wn 3. Tip : Recursive methods can be used : If the problem were selected w1 into the w2, ..., wn selected several pieces make its weight and as a T-w1, if selected w1, w2 issue into the .... wn selected several pieces make its weight and as T. Renumbered accordingly. Retrospective can also u
package problem
1. 问题描述
假设有一个能装入总体积为T的背包和n件体积分别为w1 , w2 , … , wn 的物品,能否从n件物品中挑选若干件恰好装满背包,即使w1 +w2 + … + wn=T,要求找出所有满足上述条件的解。例如:当T=10,各件物品的体积{1,8,4,3,5,2}时,可找到下列4组解: (1,4,3,2)、(1,4,5)、(8,2)、(3,5,2)。
2. 基本要求
读入T、n、w1 , w2 , … , wn
3.提示:
可利用递归方法:若选中w1 则问题变成在w2 , … , wn 中挑选若干件使得其重量之和为T- w1 ,若不选中w1,则问题变成在w2 , … , wn 中挑选若干件使得其重量之和为T 。依次类推。
也可利用回溯法的设计思想来解决背包问题。首先将物品排成一列,然后顺序选取物品装入背包,假设已选取了前i 件物品之后背包还没有装满,则继续选取第i+1件物品,若该件物品“太大”不能装入,则弃之而继续选取下一件,直至背包装满为止。但如果在剩余的物品中找不到合适的物品以填满背包,则说明“刚刚”装入背包的那件物品“不合适”,应将它取出“弃之一边”,继续再从“它之后”的物品中选取,如此重复,,直至求得满足条件的解,或者无解。
注:没压缩密码-knapsack problem achieve a package problem. Problem descr iption one would assume that the total volume of loaded backpack and T n size pieces of w1, w2, ..., wn items Can n items from the selected pieces were just filled with backpacks, even w1 w2 ... wn = T, asked to identify all of the above conditions are met solution. For example : when T = 10, the volume of items (1,8,4,3,5,2), may find the following four solutions : (1,4,3,2), (1,4,5), (8,2), (3,5,2). 2. Basic requirements read T, n, w1, w2, ..., wn 3. Tip : Recursive methods can be used : If the problem were selected w1 into the w2, ..., wn selected several pieces make its weight and as a T-w1, if selected w1, w2 issue into the .... wn selected several pieces make its weight and as T. Renumbered accordingly. Retrospective can also u
(系统自动生成,下载前可以参看下载内容)
下载文件列表
压缩包 : 21840260packageproblem.rar 列表 Package Problem\StdAfx.h Package Problem\StdAfx.cpp Package Problem\ReadMe.txt Package Problem\Package Problem.dsp Package Problem\Package Problem.dsw Package Problem\Package Problem.ncb Package Problem\Package Problem.plg Package Problem\Package Problem.cpp Package Problem\Package Problem.opt Package Problem