实现背包问题 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件物品,若该件物品“太大”不能装入,则弃之而继续选取下一件,直至背包装满为止。但如果在剩余的物品中找不到合适的物品以填满背包,则说明“刚刚”装入背包的那件物品“不合适”,应将它取出“弃之一边”,继续再从“它之后”的物品中选取,如此重复,,直至求得满足条件的解,或者无解。 注:没压缩密码
上传时间: 2014-01-18
上传用户:yxgi5
给定两个串S和T,长分别m和n,本文给出了一个找出二串间最大匹配的算法。该算法可 用于比较两个串S和T的相似程度,它与串的模式匹配有别
标签:
上传时间: 2013-12-04
上传用户:yd19890720
Winsock 2服务提供者接口( Service Provider Interface, SPI)代表着另一端的Wi n s o c k编 程(和Winsock 2API相对应)。Wi n s o c k的一端是A P I,另一端则是S P I。
标签: Winsock Interface Provider Service
上传时间: 2015-07-08
上传用户:yoleeson
上下文无关文法(Context-Free Grammar, CFG)是一个4元组G=(V, T, S, P),其中,V和T是不相交的有限集,S∈V,P是一组有限的产生式规则集,形如A→α,其中A∈V,且α∈(V∪T)*。V的元素称为非终结符,T的元素称为终结符,S是一个特殊的非终结符,称为文法开始符。 设G=(V, T, S, P)是一个CFG,则G产生的语言是所有可由G产生的字符串组成的集合,即L(G)={x∈T* | Sx}。一个语言L是上下文无关语言(Context-Free Language, CFL),当且仅当存在一个CFG G,使得L=L(G)。 *⇒ 例如,设文法G:S→AB A→aA|a B→bB|b 则L(G)={a^nb^m | n,m>=1} 其中非终结符都是大写字母,开始符都是S,终结符都是小写字母。
标签: Context-Free Grammar CFG
上传时间: 2013-12-10
上传用户:gaojiao1999
邻接矩阵类的根是A d j a c e n c y W D i g r a p h,因此从这个类开始。程序1 2 - 1给出了类的描述。程 序中,先用程序1 - 1 3中函数Make2DArray 为二组数组a 分配空间,然后对数组a 初始化,以描述 一个n 顶点、没有边的图的邻接矩阵,其复杂性为( n2 )。该代码没有捕获可能由M a k e 2 D A r r a y 引发的异常。在析构函数中调用了程序1 - 1 4中的二维数组释放函数D e l e t e 2 D
标签: 矩阵
上传时间: 2013-12-21
上传用户:lanjisu111
Hey. This some pid code for the atmega88 that I once used to control a heater. It s purpose is pretty specific, and I only wrote it to work on the mega88, so the code itself won t be too useful. It is a good place to start if you re trying to use or figure out pid though.
标签: control purpose atmega heater
上传时间: 2013-12-19
上传用户:天诚24
可以识别字符串是否符合以下文法: (1)E->TG (2)G->+TG|—TG (3)G->ε (4)T->FS (5)S->*FS|/FS (6)S->ε (7)F->(E) (8)F->i
上传时间: 2013-12-03
上传用户:songrui
递归下降分析法 (1)E->TG (2)G->+TG|—TG (3)G->ε (4)T->FS (5)S->*FS|/FS (6)S->ε (7)F->(E) (8)F->i
上传时间: 2016-07-22
上传用户:cxl274287265
给定含有n 个元素的多重集合S = {a1, a2,., an } ,1 ≤ ai ≤ n ,1 ≤ i ≤ n ,每个元素在S 中出现的次数称为该元素的重数。多重集S 中重数大于n/2 的元素称为主元素。例如,S={2,2,4,2,1,2,5,2,2,8}。多重集S 的主元素是2,其重数为6。
上传时间: 2016-08-20
上传用户:chongcongying
This a simple database management system. It doesn t use any other code (i.e. ODBC, ADO, etc.) and has it s own database file format. I wrote it because I found the other DBMSs code too bulky and hard to debug. It s designed for small applications and I doubt it could handle anything on a large scale. A sample program included in the .zip shows how everything works. The database project is a library project, so you ll have to compile and link with the .lib file to get everything working. Pros: - You have the source code so you know exactly what it is doing - Database files are very small - Small and fast code Cons: - Can t handle large amounts of records (more than 65000ish) - Doesn t support SQL (you have to search the database by cycling through the records and testing them against your constraints) - Each database file can only have one table.
标签: i.e. management database simple
上传时间: 2016-10-02
上传用户:851197153