首页 > TAG信息列表 > rnt

学习笔记——单调队列优化dp

算法 使用单调队列优化dp 废话 对与一些dp的转移方程,我们可以通过拆使它与某个区间的最值相关。 这时可以用单调队列算出区间最值,进行优化。 例题 最大子段和 题意 给出一个长度为 \(n\) 的整数序列,从中找出一段长度不超过 \(m\) 的连续子序列,使得整个序列的和最大。 思路 设 \(su

codeforces 1295 题解

codeforces 1295 题解 A. Display The Number 给你可显示的总数,让你凑个最大的数,很明显,抽象的思想就是“好钢要用在刀刃上”,如果可显示的数字越大,所消耗的越小,他自然更好。 我们观察一下各个数字的消耗情况: 0 1 2 3 4 5 6 7 8 9 6 2 5 5 4 5 6 3 7 6 数字 \(9\) 比数字

P1091-合唱队形

1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < b;i ++) 3 typedef long long ll; 4 using namespace std; 5 inline ll read() 6 { 7 ll ans = 0; 8 char ch = getchar(), last = ' '; 9 while(!isdigit(ch)) last

Leetcode-5087 Letter Tile Possibilities(活字印刷)

1 #define _for(i,a,b) for(int i = (a);i < b;i ++) 2 3 class Solution 4 { 5 public: 6 set<string> s; 7 int numTilePossibilities(string tiles) 8 { 9 s.clear();10 int rnt = 0;11 for (

Leetcode-5056 Flower Planting With No Adjacent(不邻接植花)

1 #define _for(i,a,b) for(int i = (a);i < b;i ++) 2 3 int n,m; 4 5 class Solution 6 { 7 public: 8 int color[10000]; 9 vector<vector<int>> a;10 bool OK(int t)11 {12 for(int j=0; j<a[t].si

Leetcode-1031 Maximum Sum of Two Non-Overlapping Subarrays(两个非重叠子数组的最大和)

1 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 2 class Solution 3 { 4 public: 5 int maxSumTwoNoOverlap(vector<int>& A, int L, int M) 6 { 7 vector<int> m1(A.size()),m2(A.size()); 8 m1

Leetcode-5016 Remove Outermost Parentheses(删除最外层的括号)

1 class Solution 2 { 3 public: 4 string removeOuterParentheses(string S) 5 { 6 string rnt; 7 stack<char> s; 8 s.push(S[0]); 9 10 for(int i = 1; i < S.size();i ++)11

Leetcode-5017 Sum of Root To Leaf Binary Numbers(从根到叶的二进制数之和)

1 typedef long long ll; 2 class Solution 3 { 4 public: 5 ll rnt = 0; 6 void go(TreeNode* root,int val) 7 { 8 val = (val*2+root->val)%1000000007; 9 if(root->left==NULL && root->right==NU

Leetcode-1006 Clumsy Factorial(笨阶乘)

1 #define pb push_back 2 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 3 const int maxn = 50003; 4 5 class Solution 6 { 7 public: 8 int clumsy(int N) 9 {10 if(N==1)11 return 1;12 else if

CF662C Binary Table 枚举 FWT

题面 洛谷题面 (虽然洛谷最近有点慢) 题解 观察到行列的数据范围相差悬殊,而且行的数量仅有20,完全可以支持枚举,因此我们考虑枚举哪些行会翻转。 对于第i列,我们将它代表的01串提取出来,表示为\(v[i]\), 然后我们假设有第0列,其中的第i行如果是1,表示这行将会翻转。 那么可以发现,执行完对