Question: Click to open the link
There is nothing to say about it. The LCS problem has been played blindly, but I ce twice because I and j are mixed .. Note that LCS can have an interval in the middle, but KMP does not. In addition, don't forget the dichotomy mentioned in the blog two days ago.
# Include <iostream> # include <cstring> # include <string> using namespace STD; int max (int A, int B) {return A> B? A: B;} int DP [3400] [3400]; int main () {string a, B; while (CIN> A> B) {int as =. size (); int BS = B. size (); For (INT I = 0; I <as; I ++) {for (Int J = 0; j <BS; j ++) {DP [I] [J] = 0 ;}// DP [0] [0] = 1; for (INT I = 0; I <=; I ++) {for (Int J = 0; j <= BS; j ++) {if (a [I] = B [J]) {DP [I + 1] [J + 1] = DP [I] [J] + 1 ;} else {DP [I + 1] [J + 1] = max (DP [I + 1] [J], DP [I] [J + 1]) ;}} cout <DP [as] [BS] <Endl;} return 0 ;}