随笔分类 - dp
摘要:link 普通dp: class Solution { public: int n; int minimumTimeRequired(vector<int>& jobs, int k) { n=jobs.size(); vector<int> sum(1<<n); for(int i=1;i<(1<
阅读全文
摘要:link class Solution { public: int boxDelivering(vector<vector<int>>& boxes, int portsCount, int maxBoxes, int maxWeight) { int n=boxes.size(); vector<
阅读全文
摘要:link class Solution { public: #define LL long long unordered_map<int,LL> memo; int busRapidTransit(int target, int inc, int dec, vector<int>& jump, ve
阅读全文
摘要:link 参考@vividlau https://leetcode.com/problems/new-21-game/discuss/220949/Python-3-Memorize-DFS-from-O(KW%2BW)-to-O(K-%2B-W) class Solution { public:
阅读全文
摘要:link 题解: 参考 https://www.luogu.com.cn/blog/12cow/SBCOI2020 从i到i-1,dp[k+1][j]与dp[i][k]交点左移,deque后端pop,需要多考虑i-1这个点,比较后加到deque前端。 #include <bits/stdc++.h>
阅读全文
摘要:link class Solution { public: int racecar(int target) { vector<int> dp(target+1); for(int i=1;i<=target;i++){ dp[i]=INT_MAX; int j=1; int m=1; // 先向前走
阅读全文
摘要:link 解法: maxprime存一个数的最大质因数,primeMin[i] 一个数n的质因数存在i,以n结尾所分得的最小子数组数。 class Solution { public: static const int maxn=1000000; int maxprime[maxn+1]; int
阅读全文
摘要:link 1.dfs+memo: class Solution { public: int n; int maxJumps(vector<int>& arr, int d) { n=arr.size(); vector<int> memo(n,-1); int res=0; for(int i=0;
阅读全文
摘要:link Solution: follow1 / follow 2 means the established string follow along s1 / s2.At start, follow1=follow2=1.For instance, s1 = "leetcode", s2 = "l
阅读全文
摘要:link 题解: 找n个互不相邻的披萨,求最大组合。若有两个相邻,a,b, 则吃a时b必须已经被吃掉,且是被自己吃掉;吃b时a必须已经被吃掉,且是被自己吃掉,矛盾,故互不相邻。 下面证明n个互不相邻的披萨可以顺利吃完。n=1满足条件。设n-1满足条件。n个披萨之间gap有n个,且这些gap被2n个披
阅读全文
摘要:Link Solution: f[i][j]= 1 if i cats can make up j blood. f[0][0]=1 #include <bits/stdc++.h> # define LL long long using namespace std; int n; int a[21
阅读全文
摘要:Link Solution: Get the posistions of numbers of P2 in P1, find the LIS in this position array. #include <bits/stdc++.h> # define LL long long using na
阅读全文
摘要:Link class Solution { public: int lengthOfLIS(vector<int>& nums) { int n=nums.size(); if(n==0) return 0; vector<int> dp(n+1); int len=1; dp[1]=nums[0]
阅读全文
摘要:题目链接 题解: 如果不考虑长度限制,可以用二分图染色做。 #include <bits/stdc++.h> # define LL long using namespace std; int n; int a[2001]; int col[2001]; struct Edge{ int to; i
阅读全文
摘要:题目链接 和leetcode一道题很像。。。 #include <bits/stdc++.h> # define LL long using namespace std; const int INF=0x7fffffff; const int maxn=50002; int n; int f[max
阅读全文
摘要:题目链接 题解: 对每种主件的 附件的集合 进行一次 01 背包处理,就可以先求出 对于每一种主件包括其附件的组合中,每种花费的最大价值,对应不同的方案。 在对主件进行背包处理。 需要注意的是在对每个主件的附件进行处理时,要恰好花完价钱,否则方案数会非常多。 Code: 1 #include <bi
阅读全文