動態規劃之最長公共子串行演算法

2021-04-30 14:10:58 字數 916 閱讀 1763

動態規劃之最長公共子串行演算法

演算法思想:

假設x = (x1, x2, ..., xm), y =

static

void init_xy(

void

)getchar()

;for

(i = 1; i <

= n; i++)

getchar()

;}static

void lcs_length(

void

)else

if(c[i-1]

[j]>

= c[i]

[j-1]

)else}}

printf

("the lowest common subsequence lenght = %d/n"

, c[m]

[n]);}

static

void lcs(

int i,

int j)

if(b[i]

[j]=

= 1)

else

if(b[i]

[j]=

= 2)

else

}執行結果:

[***x@localhost suanfa]$ ./a.out

please input two sequences numbers: 7 6

please input two sequences:

abcbdab

bdcaba

the lowest common subsequence lenght = 4

the lowest common subsequence is: b c b a

動態規劃之最長公共子串行

最長公共子串行簡介 舉例說明並分析 塊測試結果 乙個給定序列的子串行是在該序列中刪去若干元素後得到的序列,確切的說,若給定序列x 則另一串行z x的子串行是指存在乙個嚴格的下標序列,使得對於所有的j 0,1,k 1有zj xij。例如序列z 是序列x 的子串行,相應的遞增下標序列維。最長公共子串行問...

動態規劃之最長公共子串行

給出兩個字串,求出這樣的一 個最長的公共子串行的長度 子串行 中的每個字元都能在兩個原串中找到,而且每個字元的先後順序和原串中的 先後順序一致。sample input abcfbc abfcab programming contest abcd mnp sample output 4 2 0對於動...

動態規劃之最長公共子串行

最長公共子串行問題 time limit 1000 ms memory limit 65536 kib submit statistic discuss problem description 給定兩個序列x input 輸入資料有多組,每組有兩行 每行為乙個長度不超過500的字串 輸入全是大寫英文...