05 2020 档案
摘要:1 class UnionFind 2 { 3 public: 4 vector<int> parent; // 存储若干棵树 5 vector<int> size; // 记录每棵树包含的节点数 6 7 UnionFind(int n) 8 { 9 parent = vector<int>(n);
阅读全文
摘要:1 //dp[i][j] = x表示,戳破气球i和气球j之间(开区间,不包括i和j)的所有气球,可以获得的最高分数为x 2 //根据刚才对dp数组的定义,如果最后一个戳破气球k,dp[i][j]的值应该为: 3 // dp[i][j] = dp[i][k] + dp[k][j] 4 // + poi
阅读全文
摘要:1 // 快排的话有两个函数,一个函数是找到一个标准值,使标准值左边的都比标准值小,标准值右边的都比标准值大, 2 // 另一个就是快排的函数了,每调用一次快排的函数就将确定标准值的位置,如此循环往复,最终也就确定了最终的排序。 3 int partition(int num[],int start
阅读全文
摘要:1 // 1、当s[i] == p[j]时,dp[i][j] = dp[i - 1][j - 1] 2 // 2、当p[j] == '.'时,dp[i][j] = dp[i - 1][j - 1] 3 // 3、当p[j] == '*'时, 4 // 3.1、当s[i] != p[j - 1]时,d
阅读全文
摘要:1 void BST(TreeNode root, int target) 2 { 3 if (root.val == target) 4 // 找到目标,做点什么 5 if (root.val < target) 6 BST(root.right, target); 7 if (root.val
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int longestPalindromeSubseq(string s) 5 { 6 int n = s.size(); 7 // dp 数组全部初始化为 0 8 // 在子串s[i..j]中,最长回文子序列的长度为dp[i][j]
阅读全文
摘要:1 class Solution 2 { 3 public: 4 bool canIWin(int M, int T) 5 { 6 if (M*(M+1)/2 < T) return false; 7 if (T <= M) return true; 8 m_ = vector<int>(1 <<
阅读全文
摘要:1 状态显然有三个:开始的索引 i,结束的索引 j,当前轮到的人 2 dp[i][j][fir or sec] 3 其中: 4 0 <= i < piles.length 5 i <= j < piles.length 6 7 n = piles.length 8 for 0 <= i < n: 9
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int eraseOverlapIntervals(vector<vector<int>>& intervals) 5 { 6 if(intervals.empty() || intervals[0].empty()) return
阅读全文
摘要:1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x),
阅读全文
摘要:1 void traverse(ListNode* head) 2 { 3 if(!head) return; 4 //cout << head->val << " "; // 正序访问链表 5 traverse(head->next); 6 //cout << head->val << " ";
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices, int fee) 5 { 6 int n = prices.size(); 7 vector<vector<int>> dp(n,vector<int>(2,0))
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices) 5 { 6 if(prices.size() < 2) return 0; 7 int n = prices.size(); 8 vector<vector<int
阅读全文
摘要:1 // 一次交易由买入和卖出构成,至少需要两天。所以说有效的限制 k 应该不超过 n/2,如果超过,就没有约束作用了,相当于 k = +infinity。 2 class Solution 3 { 4 public: 5 int maxProfit(int K, vector<int>& pric
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices) 5 { 6 if(prices.empty()) return 0; 7 int n = prices.size(); 8 vector<vector<vector
阅读全文
摘要:1 dp[i][k][0 or 1] 2 0 <= i <= n-1, 1 <= k <= K 3 n 为天数,大 K 为最多交易数 4 此问题共 n × K × 2 种状态,全部穷举就能搞定。 5 6 for 0 <= i < n: 7 for 1 <= k <= K: 8 for s in {0
阅读全文
摘要:1 class Trie 2 { 3 public: 4 bool is_end; //是否以该单词结尾 5 Trie* son[26]; //该节点儿子的个数 6 Trie() 7 { 8 is_end = false; 9 for(int i = 0;i < 26;i ++) son[i] =
阅读全文
摘要:1 class Solution 2 { 3 // 状态 dp[i][j] : 表示 s 的前 i 个字符和 p 的前 j 个字符是否匹配 (true 的话表示匹配) 4 // 状态转移方程: 5 // 1. 当 s[i] == p[j],或者 p[j] == ? 那么 dp[i][j] = dp[
阅读全文

浙公网安备 33010602011771号