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
LCS(最长公共子序列)问题可以简单地描述如下: 一个给定序列的子序列是在该序列中删去若干元素后得到的序列。给定两个序列X和Y,当另一序列Z既是X的子序列又是Y的子序列时,称Z是序列X和Y的公共子序列。例如,若X={A,B,C,B,D,B,A},Y={B,D,C,A,B,A},则序列{B,C,A}是X和Y的一个公共子序列,但它不是X和Y的一个最长公共子序列。序列{B,C,B,A}也是X和Y的一个公共子序列,它的长度为4,而且它是X和Y的一个最长公共子序列,因为X和Y没有长度大于4的公共子序列。 最长公共子序列问题就是给定两个序列X={x1,x2,...xm}和Y={y1,y2,...yn},找出X和Y的一个最长公共子序列。对于这个问题比较容易想到的算法是穷举,对X的所有子序列,检查它是否也是Y的子序列,从而确定它是否为X和Y的公共子序列,并且在检查过程中记录最长的公共子序列。X的所有子序列都检查过后即可求出X和Y的最长公共子序列。X的每个子序列相应于下标集{1,2,...,m}的一个子集。因此,共有2^m个不同子序列,从而穷举搜索法需要指数时间。
上传时间: 2015-06-09
上传用户:气温达上千万的
上下文无关文法(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
We have a group of N items (represented by integers from 1 to N), and we know that there is some total order defined for these items. You may assume that no two elements will be equal (for all a, b: a<b or b<a). However, it is expensive to compare two items. Your task is to make a number of comparisons, and then output the sorted order. The cost of determining if a < b is given by the bth integer of element a of costs (space delimited), which is the same as the ath integer of element b. Naturally, you will be judged on the total cost of the comparisons you make before outputting the sorted order. If your order is incorrect, you will receive a 0. Otherwise, your score will be opt/cost, where opt is the best cost anyone has achieved and cost is the total cost of the comparisons you make (so your score for a test case will be between 0 and 1). Your score for the problem will simply be the sum of your scores for the individual test cases.
标签: represented integers group items
上传时间: 2016-01-17
上传用户:jeffery
对PL0原编译器进行了以下的扩充:1.增加以下保留字else(elsesym), for(forsym),to(tosym),downto(downtosym),return(returnsym),[(lmparen),](rmparen) 2.增加了以下的运算符:+=(eplus),-=(eminus),++(dplus),--(dminus) 取址运算符&(radsym),指向运算符@(padsym) 3.修改单词:修改不等号#为<> 4.扩充语句:(1)增加了else子句 (2)增加了for语句 5.增加运算:(1).++运算 (2).--运算;(3).+=运算 (4).-=运算;(5).&取址运算; (6).@指向运算; 6.增加类型:(1).增加多维数组a[i1][i2][i3]……[i(n-1)][i(n-2)][in] (2).增加指针类型(任何变量都能存放指针,但不支持指针的指针,如b:=@@a应该改写为c:=@a,b:=@c) 7.将过程procedure扩展为函数:(1).允许定义过程时在其后加参数(var a, var b,……..,var n) (2)允许通过指针向函数形式参数传地址;(3)允许返回值;可以用 a:=p(a,b,c….,n) 返回
标签: downtosym returnsym elsesym downto
上传时间: 2016-07-02
上传用户:saharawalker
可编程并行接口8255A完成的交通灯实验 用8255A的B端口和C端口控制12个LED的亮和灭(输出为0则亮,输出为1则灭),模拟十字路口的交通灯。 -programmable parallel interface 8255A completed, the traffic lights experimental 8255A port B and C - I control 12 LED bright and methomyl (output of 0-liang, the output of an anti), the simulation of traffic lights at a crossroads.
上传时间: 2016-08-13
上传用户:来茴
made by: kangkai data:2008.11.23 this one is used to test arm7 str71x. use a led to test GPIO. a---------P0.0 b---------P0.1 c---------P0.2 d---------P0.3 e---------P0.4 f---------P0.5 g---------P0.6 just run it and you will see the led to show 0-9 all the time.
上传时间: 2016-12-16
上传用户:moerwang
1.管理信息系统(学生成绩) 两种用户等级:管理员和用户,均用用户名和密码登陆,通过识别不同类型的用户名,进入不同的操作界面。 1) 管理员功能: i 用户管理:增加、删除用户; ii 记录录入、修改、删除 iii 查询:单项查询、多项查询、范围查询 iv 分类统计:提供有代表性的统计结果 2) 用户功能: a) 修改密码 b) 查询本用户信息 c) 修改个人信息
上传时间: 2014-01-10
上传用户:huql11633
Last week I posted an article on a simple C++ template class, XYDataArray, I used in my system development tool. The main purpose of this template class is to store and sort general data types. I needed to implement the same thing in Java, since the tool I developed has a compatible Java version. I checked the Java SDK documentation before writing my own code, and found that almost everything I needed is already there, like the C++ case.
标签: XYDataArray template article posted
上传时间: 2017-03-03
上传用户:问题问题
工业领域串口通信速度慢是个比较突出的问题, 而 F T 2 4 5 B M 能够进行 US B和并行 I / O口之间的 协议转换, 在一些条件下能够取代串口. 介绍 F T 2 4 5 B M 芯片的工作原理和功能, 并给出基于 F T2 4 5 B M 的 US B接口电路的应用设计和基于 8 9 c 5 2的汇编及 c 5 1 单片机源程序.
上传时间: 2017-05-27
上传用户:kytqcool