The government of a small but important country has decided that the alphabet needs to be streamlined and reordered. Uppercase letters will be eliminated. They will issue a royal decree in the form of a String of B and A characters. The first character in the decree specifies whether a must come ( B )Before b in the new alphabet or ( A )After b . The second character determines the relative placement of b and c , etc. So, for example, "BAA" means that a must come Before b , b must come After c , and c must come After d . Any letters beyond these requirements are to be excluded, so if the decree specifies k comparisons then the new alphabet will contain the first k+1 lowercase letters of the current alphabet. Create a class Alphabet that contains the method choices that takes the decree as input and returns the number of possible new alphabets that conform to the decree. If more than 1,000,000,000 are possible, return -1. Definition
标签: government streamline important alphabet
上传时间: 2015-06-09
上传用户:weixiao99
实现背包问题 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
DSPack is a set of Components and class to write Multimedia Applications using MS Direct Show and DirectX technologies. DSPack is designed to work with DirectX 9 on Win9X, ME, 2000, and Windows XP operating systems. Now VMR (Video Mixing Renderer) is available on all Windows Operating Systems. DSPack 2 is designed to work with Delphi 5,6,7 and CPP
标签: Applications Components Multimedia and
上传时间: 2015-07-20
上传用户:hanli8870
一套非常优秀的皮肤组件包,含源代码。 For Delphi 5, 6, 7, 2005, 2006. For C++Builder 5, 6. See bsfsb.zip with SkinBuilder sources.
标签:
上传时间: 2015-08-21
上传用户:cc1015285075
写一个程序,列出在0和1之间的所有分母不大于N的最简分数,下面是N=5时的情况: 0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1 总共有11个分数! 还需要进行排序。
标签: 程序
上传时间: 2013-12-11
上传用户:chenbhdt
北京航空航天大学刘金琨《先进pid控制》各章的源代码。都是用matlab编写,在matlab53.,6.5,7.0都可以运行。
上传时间: 2013-12-17
上传用户:ccclll
同一个数会由于采用不同的基数而使得其表现的形式是完全不一样的,在我们的学习中,我们熟悉的基数有10进制、12进制、60进制、2进制、8进制和16进制。比如数据12,如果我们用2进制表示,则它就是1100;如果用3进制表示就是110;如果用8进制表示则是14。我们的编程任务就是与数的进制(也就是基数)有关。 程序中我们会给大家很多个数对(假设每个数对的数用X和Y表示),程序需要解决的问题就是为X和Y各选择一个最小的基数,以使得这两个数在其选择的基数上是一对相等的数。 例如,12和5这个数对,我们可以为12选择基数3,为5选择基数6,这样一来12(base 3)=5(base 6),因为12(base 3)就是10进制数5,而5(base 6)也是10进制数中的5。 程序的输入是通过文件完成的。 文件中的每一行都包含一个数对X和Y,两个数通过一个或多个空格符分割,与X和Y相关联的有效基数值范围为2~36。X和Y的合理数值表示字符包括0—9和A-Z(表示数值10-35)。 文件的最后一行用一个数字0表示输入的结束。
标签:
上传时间: 2013-12-17
上传用户:skfreeman
用java GUI写的计算器程序。程序安全,健壮。多输几个小数点也只记录一个,和Windows XP 里的计算器(标准型),功能上是一样的。2+3=5,“2+3***”结果为5,不会连乘。“5*6==180”会连乘,2+3*8=40,2+3***8=40,9/0=0不报错
上传时间: 2015-09-15
上传用户:liglechongchong
上下文无关文法(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
这是一套非常优秀的皮肤组件包,是破解版,不含源代码。 For Delphi 5, 6, 7, 2005, 2006,这是目前的最新版本,等待源码版本推出。
标签:
上传时间: 2013-12-14
上传用户:linlin