提交时间:2023-12-04 13:42:06

运行 ID: 113906

# include <bits/stdc++.h> using namespace std; int dp [11451] [11451] ; int main( ) { string a , b ; cin >> a >> b ; int n = a . size( ) , m = b . size ( ) ; a = ' ' + a ; b = ' ' + b ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { dp [i] [j] = max ( dp [i - 1] [j] , dp [i] [j - 1] ) ; if ( a [i] == b [j]) { dp [i] [j] = max ( dp [i] [j] , dp [i - 1] [j - 1] + 1) ; } } } cout << dp [n] [m] << endl ; return 0; }