特點:一般給兩個字符串
- State: f[i][j] 代表了第一個sequence 的前i 個數(shù)字/字符叮趴, 配上第二個sequence的前 j個...
- Function: f[i][j] 研究 第 i 個和第 j 個的匹配關系
- Initialize : f[i][0] 和 f[0][j]
- Answer : f[n][m]
- n = len(s1)
- m = len(s2)
技巧:
狀態(tài)即是問題的答案
初始化一個二維的動態(tài)規(guī)劃時,就去初始化第0行和第0列
例子:
最長公共子序列 https://leetcode-cn.com/problems/longest-common-subsequence/
編輯距離 https://leetcode-cn.com/problems/edit-distance/
一次編輯 https://leetcode-cn.com/problems/one-away-lcci/
交錯字符串 https://leetcode-cn.com/problems/interleaving-string/submissions/