分组背包模板题

摘要: https://ac.nowcoder.com/acm/contest/86387/D #include<bits/stdc++.h> using namespace std; int a[101][30],dp[101][5005]; int main(){ int n,m;cin>>n>>m; 阅读全文
posted @ 2024-09-10 20:39 TaopiTTT 阅读(2) 评论(0) 推荐(0) 编辑

ST表求(无修)RMQ问题

摘要: 用ST表在某些出题人故意的题目中可以避免线段树导致的卡常问题 const int N=1e5+5; int pre[N],f[N][20]; void solve(){ int n,m;cin>>n>>m; pre[1]=0; for(int i=2;i<=n;i++) pre[i]=pre[i>> 阅读全文
posted @ 2024-09-10 19:59 TaopiTTT 阅读(1) 评论(0) 推荐(0) 编辑

最长公共子序列

摘要: int n;cin>>n; int ans=0; vector<int> a(n+1),b(n+1); vector<vector<int>> dp(n+1,vector<int>(n+1)); for(int i=1;i<=n;i++) cin>>a[i]; for(int j=1;j<=n;j+ 阅读全文
posted @ 2024-09-10 19:49 TaopiTTT 阅读(3) 评论(0) 推荐(0) 编辑

求最长上升子序列(动态规划入门)

摘要: int n;cin>>n; vector<int> dp(n+1),a(n+1),f(n+1); for(int i=1;i<=n;i++) cin>>a[i]; int len=1; f[1]=a[1]; for(int i=2;i<=n;i++){ int l=0,r=len,mid,ans; 阅读全文
posted @ 2024-09-10 19:45 TaopiTTT 阅读(2) 评论(0) 推荐(0) 编辑

树状数组求区间最大小值

摘要: const int N=5e5+5; const int INF=0x3f3f3f3f; int n,q; int a[N],trmx[N],trmn[N]; //将原来的累加改为求最值 void add(int x,int k){ while(x<=n){ trmx[x]=max(trmx[x], 阅读全文
posted @ 2024-09-10 19:41 TaopiTTT 阅读(2) 评论(0) 推荐(0) 编辑

树状数组求逆序对

摘要: int n; struct st{ int v,id; }a[N]; int tr[N],rk[N]; void add(int x,int k){ while(x<=n){ tr[x]+=k; x+=lowbit(x); } } int query(int x){ int res=0; while 阅读全文
posted @ 2024-09-10 19:40 TaopiTTT 阅读(1) 评论(0) 推荐(0) 编辑

CF1913C Game with Multiset

摘要: 题目 In this problem, you are initially given an empty multiset. You have to process two types of queries: ADD \(x\) — add an element equal to \(2^{x}\) 阅读全文
posted @ 2024-06-06 21:36 TaopiTTT 阅读(3) 评论(0) 推荐(0) 编辑

CF1881D 质因数分解与重新分配

摘要: 题目 You are given an array \(a\) consisting of \(n\) positive integers. You can perform the following operation on it: Choose a pair of elements \(a_i\ 阅读全文
posted @ 2024-06-05 00:36 TaopiTTT 阅读(3) 评论(0) 推荐(0) 编辑

前缀和解决字符串变化问题

摘要: 题目 小苯有一个长度为\(n\)的字符串\(s\),每次操作他可以选择一个位置的字母将其的大小写反转,也就是说如果字符是小写,则操作后会变成大写,如果字符是大写则反之。 他现在希望将\(s\)变为:“前面若干字符是大写,后面的字符全是小写”的样子,例如:"AABBccdd"。(注意:全大写和全小写均 阅读全文
posted @ 2024-06-03 21:13 TaopiTTT 阅读(6) 评论(0) 推荐(0) 编辑

窗口判断子数组排列

摘要: 题目 给定一个数组,试求有多少个长度为\(k\)的连续子数组是排列。 https://ac.nowcoder.com/acm/problem/273933 Input 第一行输入两个正整数\(n\),\(k\),代表小红拿到的数组大小和连续子数组的大小。 第二行输入\(n\)个正整数\(a_i\), 阅读全文
posted @ 2024-06-03 20:40 TaopiTTT 阅读(2) 评论(0) 推荐(0) 编辑