很好的DP思路,字符串比较次数

时间:2022-08-01 19:55:18

题目:

https://leetcode.com/problems/distinct-subsequences/?tab=Description

 

一般没有明显思路的情况下,都要想想DP,用下Divide-and-Conque

 

下面的思路很好,很清晰

https://discuss.leetcode.com/topic/9488/easy-to-understand-dp-in-java/2

 

一个矩阵,如果字符不一样,那就用左侧的;如果字符一样,那就左侧+上方的。

An example:
S: [acdabefbc] and T: [ab]

first we check with a:

           *  *
      S = [acdabefbc]
mem[1] = [0111222222]
then we check with ab:

               *  * ]
      S = [acdabefbc]
mem[1] = [0111222222]
mem[2] = [0000022244]