I. Dynamic Programming method
Often encountering complex problems cannot be easily decomposed into several child problems, but a series of child problems will be decomposed. The problem solving time can be increased by the scale of the problem by simply using the method of decomposing the big problem into a child problem and synthesizing the solution of the problem.
In order to save time for repeating the same sub problem, an array is introduced, whether or not they are useful for the final solution, and the solution of all the child problems is in the array, which is the basic method of dynamic programming.
Second, the question: the longest common character subcode sequence (LCS) for two character sequences
Problem Description: The subsequence of a character sequence is a sequence of characters that is formed from a given sequence of characters that is arbitrarily (not necessarily continuous) to remove several characters (which may not be removed). The given sequence of characters is x= "X0,x1,...,xm-1", the sequence y= "Y0,y1,...,yk-1" is a subsequence of x, and there is a strictly ascending subscript sequence of x <i0,i1,...,ik-1>, which makes for all j=0,1,...,k-1, has xij=yj. For example, x= "Abcbdab", y= "bcdb" is a subsequence of X.
Third, analysis
Consider how the longest common subsequence problem can be decomposed into sub problems, set a= "A0,a1,...,am-1", b= "B0,b1,...,bm-1", and z= "Z0,z1,...,zk-1" as their longest common subsequence. It is not difficult to prove the following nature:
(1) If am-1=bn-1, then zk-1=am-1=bn-1, and "Z0,z1,...,zk-2" is a longest common subsequence of "a0,a1,...,am-2" and "b0,b1,...,bn-2";
(2) If the am-1!=bn-1 is zk-1!=am-1, the implication of "Z0,z1,...,zk-1" is a longest common subsequence of "a0,a1,...,am-2" and "b0,b1,...,bn-1";
(3) If the am-1!=bn-1 is zk-1!=bn-1, the implication "z0,z1,...,zk-1" is one of the longest common subsequence of "a0,a1,...,am-1" and "b0,b1,...,bn-2".