所谓的动态规划 是一种手段 不像树或者图或者Math之类的题目一样 看到题目就知道这个是属于什么题目 应该用什么方式去做。
比如说 树的话 就是递归或者各种遍历
图的话就是BFS和DFS方式
而动态规划的题目 大多数是给一些数组(一维或者二维)然后让你去求一些最大最小值 或者是能否的问题。
什么情况下会考虑用这种方法?
当这道题不是一些典型的树 图 链表 Math 之类的题目 也不是一些需要用特殊数据结构比如并查集 PQ, Min Stack去做,而且用馋鬼的一些小技巧也挣不出来的时候 就要考虑这道题目是不是可以用DP/Backtracking/Greedy做
-
- Climbing Stairs
-
- Min Cost Climbing Stairs
-
- Best Time to Buy and Sell Stock
-
- Best Time to Buy and Sell Stock II
-
- Best Time to Buy and Sell Stock III
-
- Best Time to Buy and Sell Stock IV
-
- Best Time to Buy and Sell Stock with Cooldown
-
- House Robber
-
- House Robber II
-
- Range Sum Query - Immutable
-
- Decode Ways
-
- Unique Paths
-
- Unique Paths II
-
- Triangle
-
- Minimum Falling Path Sum
-
- Minimum Falling Path Sum II
-
- Perfect Squares
-
- Longest Palindromic Substring
-
- Video Stitching
-
- Longest String Chain
-
- Longest Common Subsequence
-
- Delete Operation for Two Strings
-
- Minimum ASCII Delete Sum for Two Strings
-
- Minimum Insertion Steps to Make a String Palindrome
-
- Maximal Square
-
- Jump Game V
-
- Number of Paths with Max Score
-
- Count Square Submatrices with All Ones
-
- Number of Ways to Stay in the Same Place After Some Steps
-
- Counting Bits
-
- Greatest Sum Divisible by Three
-
- Edit Distance
-
- Coin Change
-
- Coin Change 2
-
- Count Vowels Permutation
-
- Largest Divisible Subset
-
- Kth Ancestor of a Tree Node
-
- Find Two Non-overlapping Sub-arrays Each With Target Sum
-
- Target Sum
-
- Dungeon Game
-
- Unique Binary Search Trees
-
- Unique Binary Search Trees II
- 方法二:看了stefan的答案,更正一下自己的方法,lo==hi是没必要的,之前因为先考虑这个因素,没有删掉。deepcopy可以写成别的形式,在内循环生成root节点,而不是在外层生成一个再去拷贝。记忆化搜索也是没有必要的。用时比原来快了3倍。
-
- House Robber III
-
- Count Submatrices With All Ones
-
- Stone Game II
-
- Stone Game IV
-
- Number of Sub-arrays With Odd Sum
-
- Word Break
-
- Word Break II
-
- Restore The Array
-
- Get the Maximum Score
-
- Minimum Number of Days to Eat N Oranges
-
- Minimum Swaps To Make Sequences Increasing
-
- New 21 Game
-
- Soup Servings
-
- Minimum Cost For Tickets
-
- Matchsticks to Square
-
- Champagne Tower
-
- Predict the Winner
-
- Out of Boundary Paths
-
- Knight Probability in Chessboard
-
- Palindrome Partitioning II
-
- Partition Array for Maximum Sum
-
- Domino and Tromino Tiling
-
- Longest Increasing Path in a Matrix
-
- Shopping Offers
-
- Maximum Product Subarray
- LCP 20. 快速公交
-
- Stone Game
-
- Longest Increasing Subsequence
-
- Number of Longest Increasing Subsequence
- 面试题 17.08. 马戏团人塔
- 面试题 08.13. 堆箱子
-
- Maximum Non Negative Product in a Matrix
- 面试题 08.14. 布尔运算
- 面试题 17.13. 恢复空格
-
- Minimum One Bit Operations to Make Integers Zero
-
- Longest Arithmetic Subsequence
-
- 分割等和子集
-
- Longest Consecutive Sequence
-
- Matrix Block Sum
-
- Best Team With No Conflicts
-
- Binary Trees With Factors
-
- Delete and Earn
-
- Arithmetic Slices