随笔 - 530
文章 - 0
评论 - 3
阅读 -
10098
02 2023 档案
一本通1424: 区间覆盖
摘要:给一些区间,挑出最少的区间覆盖 【0,L】 贪心:从0往后,每次挑出R 点最大的 #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std ; const int
阅读全文
acwing 281 硬币
摘要:给定n种硬币,其中第 i种硬币的面值为 Ai,共有p iCi 个。 从中选出若干个硬币,把面值相加,若结果为sS ,则称“面值sS 能被拼成”。 求 1∼M 1~M之间能被拼成的面值有多少个。 #include <iostream> #include <cstring> using namespac
阅读全文
acwing 287积蓄程度
摘要:除了源点之外,树中所有度数为1 的节点都是入海口,可以吸收无限多的水,我们称之为汇点。 也就是说,水系中的水从源点出发,沿着每条河道,最终流向各个汇点。 问最大流量 f[ x] = sum{ min( f[y] ,z) } 换根,考虑 g[x] 流向所有(包括x往上) 时的最大流量 g[y]=f[y
阅读全文
#10051. 「一本通 2.3 例 3」Nikitosh 和异或
摘要:求两段不相交子序列,他们异或和的 和最大 #include<iostream> #include <algorithm> #include <cstring> using namespace std; const int N =4e5+4; int ch[N*32][2],ans; int tot=
阅读全文
The XOR Largest Pair
摘要:从序列A中选出两个进行异或运算,得到的结果最大是多少? 两个数二进制插入Trie 每次遍历时尽量走反 #include<iostream> #include <algorithm> #include <cstring> using namespace std; const int N =1e5+4;
阅读全文
Shortest Prefixes POJ - 2001
摘要:给一些串,问每个串的唯一前缀,若不存在输出本身 #include<iostream> #include <cstring> #include <algorithm> using namespace std ; const int N =1e5; int ch[N][30],tot,val[N]; v
阅读全文
1471:【例题1】Phone List
摘要:给一些字符串 , 问 是否有两个串有前缀关系 字典树节点维护结束标记 val[ ] , 跑的时候检查一下 #include<iostream> #include <algorithm> #include <cstring> using namespace std; const int N=1e5+4
阅读全文
Problem C HDU - 5687
摘要:现在有个字典要支持一下操作 1、insert : 往神奇字典中插入一个单词 2、delete: 在神奇字典中删除所有前缀等于给定字符串的单词 3、search: 查询是否在神奇字典中有一个字符串的前缀等于给定的字符串 字典树每个节点维护 sum[ i ] delete 操作: 先查询包含该串的串个数
阅读全文
统计难题 HDU - 1251
摘要:给一些字符串,问以某个串为前缀的串有几个 #include<iostream> #include <algorithm> #include <cstring> using namespace std; const int N=5e5+4; char num[80]; int len,sum[N];
阅读全文
Jzzhu and Sequences CF450B
摘要:其中 f(1)=x0,f(2)=y0, f( i )=f( i-1 )+f( i+1 ),求 f(n) #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define N 2 int mod
阅读全文
Reading comprehension HDU - 4990
摘要:ans=0; for(i=1;i<=n;i++) { if(i&1)ans=(ans*2+1)%m; else ans=ans*2%m; } 使用矩阵快速幂计算 f[n ] f[n] = f[n-1]+f[n-2]*2 +1 { f[n] ,f[n-1] ,1 } = { f[n-1] ,f[ n-
阅读全文
Fibonacci 第 n 项
摘要:#include <iostream> #include <cmath> #include <algorithm> using namespace std; #define N 2 int mod; #define int long long struct matrix { int a[N+2][N
阅读全文
矩阵快速幂
摘要:求矩阵的 k 次幂 #define int long long #define N 3 int mod =1e9+7; struct matrix { int a[N+2][N+2]; }; int n; void init_(matrix &x){ memset(x.a,0,sizeof x.a)
阅读全文
CF1637D Yet Another Minimization Problem
摘要:定义某数组 xx 的权值为 sum{ sum{ a[i]+b[i] } } i<j<n 现在,给定两个长度为 nn 的数组 a,ba,b。你可以执行若干次操作,每次操作选择一个下标 ii,并交换 ai,bi 。 求在进行操作之后两个数组的权值之和最小能够达到多少。 = (a1+....an )^2
阅读全文
CF580D Kefa and Dishes
摘要:有n个菜(0<n<=18)第i个菜的满意度为a[i ](0<=ai<=10^9),有k个规则,如果在吃完第xi个菜之后吃了第yi个菜, 会额外获得ci的满意度。kefa要吃m道任意的菜(0<m<=n),但是他希望自己吃菜的顺序得到的满意度最大 f[j][i] = f[j^(1<<i) ] [k ]+
阅读全文
CF607B zuma
摘要:从序列中每次消去回文串,问最少几次消除完 #include <iostream> #include <cstring> using namespace std ; const int N=503,inf=0x3f3f3f3f; int f[N][N],a[N],n; signed main(){ i
阅读全文
The Great Mixing CF788C
摘要:从序列中找一些数,使平均数>=m,问最少取几个数》 #include <iostream> #include<algorithm> #include <cstring> #define IOS std::ios::sync_with_stdio(0) using namespace std; con
阅读全文
Cut Ribbon CodeForces - 189A
摘要:给3个数字, 求组成n 的方案中 数字个数最多的 ? #include <iostream> #include<queue> #include <cstring> #define IOS std::ios::sync_with_stdio(0) using namespace std; const
阅读全文
CF855B Marvolo Gaunt's Ring
摘要:给了三个数: p,q,r(−1e9<=p,q,r<=1e9)p,q,r(−1e9<=p,q,r<=1e9) 然后给了n个数a1,a2...an(−1e9<=ai<=1e9)a1,a2...an(−1e9<=ai<=1e9) 求找出三个数ai,aj,ak(1<=i<=j<=k<=n)ai,a
阅读全文
CF245H Queries for Number of Palindromes
摘要:对字符串s,多次询问,给你两个数L和R,问在字符串区间l到r的字串中,包含多少回文串。 #include <iostream> #include<queue> #include <cstring> #define IOS std::ios::sync_with_stdio(0) using name
阅读全文
CF1312E Array Shrinking
摘要:给你一个长度为 n(1≤n≤500)n(1≤n≤500) 的数组 aa,每次你可以进行以下两步操作: 找到 i∈[1,n)i∈[1,n),使得 ai=ai+1ai=ai+1; 将 它们 替换为 ai+1ai+1。 每轮操作之后,显然数组的长度会减小 11,问剩余数组长度的最小值。 #inclu
阅读全文
CF 1061C
摘要:给定一个序列 A,求有多少非空序列 B 满足 B 是 A 的子序列 并且 ∀ k ∈ [1,lenb], k∣bk∀ k ∈ [1,lenb], k∣bk, // f[i][j]= f[i-1][j] + (f[i-1][j-1] ,a[i]%j==0 ) 优化: 枚举 a[i] 的因数作为 j
阅读全文
CF 455A
摘要:有 n个数,每一次取一个 x ,将其删除,并将所有值为x+1 与 x−1 的数都删除,ans 加上x ,求最后最大的ans 的值. (1<=a[i]<=1e5) 考虑 f[ i ] 1~i 的数字 最大ans ,f[i]=max{ f[i-1], f[i-2]+cnt[i] *i ) #includ
阅读全文
python trash
摘要:x,y= map(int,input().split()) print(x," ",y) 9TTXwpbgdWhtkB3 a=[32,43,21,431] a.append(3) a.remove(21) print(a) a.extend([98,21]) print(a) a.insert(0,
阅读全文
CF 191A
摘要:大意是:给你nn个字符串,将这些字符串拼接,求一个最长的序列,使这个其中每个串的最后一个字母与第一个字母相同(最后一个串的最后一个字母与第一个串的第一个字母相同),而且后面的串只能接在前面的串的后边。 f[ch][ch] 首尾为ch , 的最大长度 对某个 串s , f[j][y]= max{ f[
阅读全文
POJ 1149 PIGS
摘要:https://vjudge.net/problem/POJ-1149 #include <iostream> #include<queue> #include <cstring> #define IOS std::ios::sync_with_stdio(0) using namespace st
阅读全文
P3870 开关
摘要:对01序列 区间异或,求区间和 #include <iostream> #include<queue> #include <cstring> #define IOS std::ios::sync_with_stdio(0) using namespace std; #define rt1 rt<<1
阅读全文
POJ 3345 Bribing FIPA
摘要:#include <iostream> #include <map> #include <algorithm> #include <cstring> using namespace std; const int N =203 ,M =N; typedef long long ll; int n,m,
阅读全文
P2016 战略游戏
摘要:#include <bits/stdc++.h> using namespace std ; const int N=1600,M=5*N; int n,in[N],nxt[M],go[M],hd[N],all=1,f[N][2]; void add(int x,int y){ go[++all]=
阅读全文
P4302 字符串折叠
摘要:https://www.luogu.com.cn/problem/P4302 求字符串的最短折叠 AAAAAAAAAABABABCCD 的最短折叠为: 9(A)3(AB)CCD。 #include <iostream> #include <cstring> #include <algorithm>
阅读全文
acwing 318. 划分大理石
摘要:多重背包及优化 #include <bits/stdc++.h> using namespace std ; const int N=5e5+10; int c[N],S,n,f[N]; int solve(){ int i,j; S=0; memset(f,0,sizeof f); int fla
阅读全文
acwing 316. 减操作
摘要:类似背包 f[i][sum] |= f[i-1][sum-a[i] ] ,这里设置为1或-1 #include <bits/stdc++.h> using namespace std ; const int N=2e4+10; const int D=1e4; int n,m,a[N],f[102]
阅读全文
AcWing 372. 棋盘覆盖
摘要:给n*n的方格图铺满1*2 的长条,且某些位置不能铺,问最多能放多少个长条 #include <iostream> #include<queue> #include <vector> #include <cstring> using namespace std; const int N =110 ,
阅读全文
二分图 笔记
摘要:二分图最大匹配 1.匈牙利算法: 做法是 u 尽量 匹配 v , 如果v已有配对 y,就重新配对 y https://www.luogu.com.cn/record/128670058 2. 网络流解决 性质: 最大独立集= 点数-最大匹配 最小顶点集覆盖数= 最大匹配
阅读全文
#10108. 「一本通 3.7 练习 2」Ant Trip
摘要:无向图一笔画需要多少次(欧拉路径的条数) 答案:奇数点的个数 / 2 这题需要维护联通块,用并查集即可 #include <iostream> #include <algorithm> #include <cstring> #include <stack> using namespace std ;
阅读全文
poj 2230
摘要:求一个无向图的欧拉回路,但要求每条边正反过一次 当作有向图,打标记只打一条边 #include <iostream> #include <algorithm> #include <cstring> #include <stack> using namespace std ; const int N=
阅读全文
#10105. 「一本通 3.7 例 1」欧拉回路
摘要:求欧拉回路( dfs ) #include <bits/stdc++.h> using namespace std ; const int N=1e6+3,M=2e6+3; inline int read(){ int res = 0, flag = 1; char ch = getchar();
阅读全文
1515:网络协议
摘要:板子题 缩点找出入度为0的点 即可 第二问 max(p,q) #include <bits/stdc++.h> using namespace std ; const int N=103; vector<int> g[N],graph[N]; int n,pool,dfn[N],low[N],in[
阅读全文
欧拉路 笔记
摘要:A.对于欧拉路径: 有向图:图连通,有一个顶点出度大入度1,有一个顶点入度大出度1,其余都是出度 == 入度 无向图:图连通,只有两个顶点是奇数度,其余都是偶数度 B.对于欧拉回路: 有向图:图连通,所有的顶点出度 == 入度 无向图:图连通,所有顶点都是偶数度
阅读全文
判负环
摘要:看 某个点的入队次数 times>=n #include <bits/stdc++.h> using namespace std ; const int N=1e5+2,inf=0x7f7f3f; struct E{ int y,z; E(int y0,int z0){ y=y0,z=z0; } f
阅读全文
LCA 板子
摘要:本例 求树上两点的距离 #include <bits/stdc++.h> using namespace std ; const int N=5*1e6+2,M=5*N; int nxt[M],hd[N],all,go[M],n; int dep[N],f[N][22]; void add(int
阅读全文
P3629 巡逻
摘要:在边权都为1的 树上加1条或者2条边(边权为1) ,从1出发遍历所有点,使得总路程最短 #include <bits/stdc++.h> using namespace std ; const int N=1e5+2,M=2*N; int nxt[M],w[M],go[M],hd[N],all=1;
阅读全文
队列(手写
摘要:struct Q{ int q[N],hh=1,tt=0; void push(int x){ q[++tt]=x; } void pop(){hh++;} bool empty(){return hh<=tt?0:1;} int front(){ return q[hh]; } };
阅读全文