PackageProblem

所属分类:数据结构
开发工具:Visual C++
文件大小:9KB
下载次数:33
上传日期:2006-06-01 09:07:11
上 传 者vegaliming
说明:  实现背包问题 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 description 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\StdAfx.h (667, 2006-05-30)
Package Problem\StdAfx.cpp (302, 2006-05-30)
Package Problem\Package Problem.dsp (4646, 2006-05-30)
Package Problem\Package Problem.dsw (555, 2006-05-30)
Package Problem\Package Problem.ncb (50176, 2006-05-30)
Package Problem\Package Problem.plg (1398, 2006-05-30)
Package Problem\Package Problem.cpp (596, 2006-05-30)
Package Problem\Package Problem.opt (53760, 2006-05-30)
Package Problem (0, 2006-05-30)

======================================================================== CONSOLE APPLICATION : Package Problem ======================================================================== AppWizard has created this Package Problem application for you. This file contains a summary of what you will find in each of the files that make up your Package Problem application. Package Problem.dsp This file (the project file) contains information at the project level and is used to build a single project or subproject. Other users can share the project (.dsp) file, but they should export the makefiles locally. Package Problem.cpp This is the main application source file. ///////////////////////////////////////////////////////////////////////////// Other standard files: StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named Package Problem.pch and a precompiled types file named StdAfx.obj. ///////////////////////////////////////////////////////////////////////////// Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize. /////////////////////////////////////////////////////////////////////////////

近期下载者

相关文件


收藏者