摘要: 题目 动态规划 dp[i][0] 表示当天什么都不操作 dp[i][1] 表示当天买进 dp[i][2] 表示当天卖出 状态转移就好写出了 class Solution { public: long long int dp[10005][3]; int maxProfit(vector<int>& 阅读全文
posted @ 2020-06-03 15:34 Shendu.CC 阅读(97) 评论(0) 推荐(0) 编辑
摘要: 题目 动态就区间和,线段树,树状数组都可以 class NumArray { public: int n; int c[100005]; vector<int> nums; NumArray(vector<int>& nums) { this->nums = nums; memset(c,0,siz 阅读全文
posted @ 2020-06-03 15:30 Shendu.CC 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 题目 简单小模拟 class Solution { public: std::string::size_type sz = 0; bool isAdditiveNumber(string num) { for (int i = 0; i < num.length(); i++) { for (int 阅读全文
posted @ 2020-06-03 15:29 Shendu.CC 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 题目 二维的,那就二维前缀和数组 class NumMatrix { public: int prefix[1005][1005]; NumMatrix(vector<vector<int>>& matrix) { memset(prefix,0,sizeof(prefix)); for(int i 阅读全文
posted @ 2020-06-03 15:28 Shendu.CC 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 题目 求区间,固定的数组,用前缀和数组 class NumArray { public: vector<int> prefix; NumArray(vector<int>& nums) { prefix.push_back(0); for(int i=0;i<nums.size();i++) { p 阅读全文
posted @ 2020-06-03 15:26 Shendu.CC 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 题目 删除最少的括号,让所有括号匹配起来。 大部分都是用DFS,或者BFS。我用的DP,也可以过 dp[i][j] :means it need remove at least dp[i][j] characters to get vaild parenthese from position i t 阅读全文
posted @ 2020-06-03 15:22 Shendu.CC 阅读(147) 评论(0) 推荐(0) 编辑