上下文無關文法(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