1006 最長公共子串行Lcs

2021-07-10 18:22:33 字數 999 閱讀 2750

給出兩個字串a b,求a與b的最長公共子串行(子串行不要求是連續的)。

比如兩個串為:

abcicba

abdkscab

ab是兩個串的子串行,abc也是,abca也是,其中abca是這兩個字串最長的子串行。

input

第1行:字串a

第2行:字串b

(a,b的長度 <= 1000)

output

輸出最長的子串行,如果有多個,隨意輸出1個。
input示例

abcicba

abdkscab

output示例

abca#include #include #include #include #include #include #include #include #include #include using namespace std;

#define esp 1e-8

const double pi = acos(-1.0);

const int inf = 1000000005;

const long long mod = 1000000007;

//freopen("in.txt","r",stdin); //輸入重定向,輸入資料將從in.txt檔案中讀取

//freopen("out.txt","w",stdout); //輸出重定向,輸出資料將儲存在out.txt檔案中

char a[1005], b[1005],c[1005];

int dp[1005][1005];

int main()

else}}

for (i = la, j = lb; i >= 1 && j >= 1; )

else

}for (i = tot - 1; i >= 0; -- i)

printf("%c", c[i]);

printf("\n"); }

}

1006 最長公共子串行Lcs

基準時間限制 1 秒 空間限制 131072 kb 分值 0 難度 基礎題 給出兩個字串a b,求a與b的最長公共子串行 子串行不要求是連續的 比如兩個串為 abcicba abdkscab ab是兩個串的子串行,abc也是,abca也是,其中abca是這兩個字串最長的子串行。input 第1行 字...

1006 最長公共子串行Lcs

給出兩個字串a b,求a與b的最長公共子串行 子串行不要求是連續的 比如兩個串為 abcicba abdkscab ab是兩個串的子串行,abc也是,abca也是,其中abca是這兩個字串最長的子串行。input 第1行 字串a 第2行 字串b a,b的長度 1000 output 輸出最長的子串行...

1006 最長公共子串行Lcs

給出兩個字串a b,求a與b的最長公共子串行 子串行不要求是連續的 比如兩個串為 abcicba abdkscabab是兩個串的子串行,abc也是,abca也是,其中abca是這兩個字串最長的子串行。收起第1行 字串a 第2行 字串b a,b的長度 1000 輸出最長的子串行,如果有多個,隨意輸出1...