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