You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicvoidrecur(intlevel, intparam) {
//1、 terminator 终止条件if (level > MAX_LEVEL) {
//2、 process result 处理过程return;
}
//3、 process current logic 处理当前逻辑process(level, param);
//4、 drill down 下沉,进入下层recur(level: level + 1, newParam);
//5、 restore current status 清理值状态
}
递归、分治、动态规划
递归
自己调用自己
代码模板
分治
分而治之 Divide & Conquer
思路
本质 :寻找重复性
动态规划 DP
理解:即动态递推, 寻找递推方程、递推公式
模式:顺推,动态递推,缓存中间值
常见问题及递推公式
不同路径
f(x, y) = f(x-1, y) + f(x, y-1)
爬楼梯
f(n) = f(n - 1) + f(n - 2) , f(1) = 1, f(0) = 0
打家劫舍
最小路径和
最小路径和
股票买卖
高级动态规划
复杂来源:
状态拥有更多维度(二维、三维、或者更多、甚至需要压缩)
状态方程更加复杂
本质:考察 内功、逻辑思维、数学
题型列举
爬楼梯问题改进
https://leetcode-cn.com/problems/min-cost-climbing-stairs/
编辑距离
字符串
基础知识
基础问题
字符串操作问题
Anagram异位词问题
回文串问题
高级问题及算法
字符串匹配算法
暴力法
Rabin-Karp 算法
KMP 算法