prolog 找路例子程序:
=== === === === === ===
Part 1-Adding connections
Part 2-Simple Path
example
| ?- path1(a,b,P,T).
will produce the response:
T = 15
P = [a,b] ?
Part 3 - Non-repeating path
As an example, the query:
?- path2(a,h,P,T).
will succeed and may produce the bindings:
P = [a,depot,b,d,e,f,h]
T = 155
Part 4 - Generating a path below a cost threshold
As an example, the query:
?- path_below_cost(a,[a,b,c,d,e,f,g,h],RS,300).
returns:
RS = [a,b,depot,c,d,e,g,f,h] ?
RS = [a,c,depot,b,d,e,g,f,h] ?
no
==================================
標簽:
Part
connections
example
prolog
上傳時間:
2015-04-24
上傳用戶:ljt101007
This section contains a brief introduction to the C language. It is intended as a tutorial on the language, and aims at getting a reader new to C started as quickly as possible. It is certainly not intended as a substitute for any of the numerous textbooks on C. 2. write a recursive function FIB (n) to find out the nth element in theFibanocci sequence number which is 1,1,2,3,5,8,13,21,34,55,…3. write the prefix and postfix form of the following infix expressiona + b – c / d + e * f – g * h / i ^ j4. write a function to count the number of nodes in a binary tr
標簽:
introduction
the
contains
intended
上傳時間:
2013-12-23
上傳用戶:liansi
上下文無關文法(Context-Free Grammar, CFG)是一個4元組G=(V, T, S, P),其中,V和T是不相交的有限集,S∈V,P是一組有限的產(chǎn)生式規(guī)則集,形如A→α,其中A∈V,且α∈(V∪T)*。V的元素稱為非終結符,T的元素稱為終結符,S是一個特殊的非終結符,稱為文法開始符。
設G=(V, T, S, P)是一個CFG,則G產(chǎn)生的語言是所有可由G產(chǎn)生的字符串組成的集合,即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
本題要完成的是一組簡單C表達的運算。所有表達式存放在文件 CExpression.txt 中,每個表達式一行。每行的長度不會超過80個字符。文件最后有一個空行表示結束。
每個表達式,只包含簡單的整數(shù)變量和限定的一些操作符,表達式中沒有常量。總共有26個可能出現(xiàn)在表達式中的變量,分別命名為 a,b,...,z。每個變量最多出現(xiàn)一次。26個變量的初值分別為1,2,...,26。
表達式中的操作符,包括:兩個二元操作符 +, -,表示加,減運算。例如,表達式a+c-d+b(即1+3-4+2)的結果為2。 單獨一個-號不能放在變量前面,表示負數(shù)。
表達式中還包含兩個一元運算符:++,--,表示加一和減一運算。它們既可以出現(xiàn)在一個變量的前面、也可以出現(xiàn)在后面。如果出現(xiàn)在變量前面,則表示先對變量進行加一/減一運算,然后變量值參與表達式計算。如果出現(xiàn)在變量后面,則表示變量的原值參與表達式計算,表達式計算完之后,變量值加一/減一。
例如,表達式 -- c + b-- 的結果為 4, 表達式計算完之后, b,c的值分別為1,2
輸出格式要求:輸出直接顯示在屏幕上。對于每個表達式,第一行輸出表達式的內容。第二行輸出表達式的值,后面幾行輸出參與運算的各個變量的結果值。
標簽:
CExpression
txt
運算
表達式
上傳時間:
2017-01-17
上傳用戶:cjf0304