随笔分类 - 动态规划
摘要:图解找递推公式 const int N = 20; class Solution { public: int dp[N]; int numTrees(int n) { dp[0] = 1; for (int i = 1; i <= n; i ++) for (int j = 0; j <= i -
阅读全文
摘要:const int N = 60; class Solution { public: int dp[N]; int integerBreak(int n) { dp[2] = 1; for (int i = 3; i <= n; i ++) for (int j = 1; j < i; j ++)
阅读全文
摘要:dfs(超时) class Solution { public: int res = 0; void dfs(int x, int y, int m, int n) { if (x == m && y == n) res ++; if (x + 1 <= m) dfs(x + 1, y, m, n)
阅读全文
摘要:动态规划 const int N = 1000; class Solution { public: int dp[N]; int minCostClimbingStairs(vector<int>& cost) { dp[0] = cost[0]; dp[1] = cost[1]; for (int
阅读全文
摘要:动态规划 const int N = 50; class Solution { public: int dp[N]; int climbStairs(int n) { dp[0] = 1; dp[1] = 1; for (int i = 2; i <= n; i ++) dp[i] = dp[i -
阅读全文
摘要:动态规划 const int N = 40; class Solution { public: int dp[N]; int fib(int n) { dp[1] = 1; for (int i = 2; i <= n; i ++) dp[i] = dp[i - 1] + dp[i - 2]; re
阅读全文