随笔 - 530  文章 - 0  评论 - 3  阅读 - 10098 
10 2022 档案
最长公共上升子序列
摘要:n^3 #include <iostream> #include <algorithm> #include<cstring> #include <vector> using namespace std; const int N=600; int n,m,a[N],b[N],p[N][N],f[N][ 阅读全文
posted @ 2022-10-31 23:02 towboat 阅读(17) 评论(0) 推荐(0) 编辑
uva 12563 Jin Ge Jin Qu hao
摘要:01背包,这题设计状态f[i][j] 为刚好用完时间 j 时的歌曲数,这样方便找到用时(初始化设置一下就好 #include <iostream> #include <algorithm> #include<cstring> using namespace std; const int N=53,M 阅读全文
posted @ 2022-10-31 20:04 towboat 阅读(10) 评论(0) 推荐(0) 编辑
poj 2392 Space Elevator
摘要:给出了一些砖块,砖块有高度,最高可以达到的高度(高度限制)和数量,问可以用这些砖块堆的最大高度 f[i][j] 考虑前i块,能否堆出高度为j f[i][j] | =f[i-1][j-k*h[i] ] 注意先排个序,按照 limit[i] 从小到大 枚举 j #include <iostream> # 阅读全文
posted @ 2022-10-31 15:56 towboat 阅读(19) 评论(0) 推荐(0) 编辑
uva 590
摘要:一共有n座城市,要在这n座城市旅游k天,从城市1出发,第k天到达城市n。 输入有n*(n-1)行,每n-1行代表i到除了i之外的其他城市航班的天数以及价格。 求最小花费。 #include <iostream> #include <algorithm> using namespace std; co 阅读全文
posted @ 2022-10-31 00:30 towboat 阅读(14) 评论(0) 推荐(0) 编辑
uva 473
摘要:有n首歌,每首时长Ti,要把这n首歌装进m个光盘里面,每个光盘最多能存的时长为t. 要求这些歌在光盘里面要按照所给歌的先后顺序存入,不能改变前后顺序. 例如有4首歌,按顺序给出他们的时长:1,2,3,4. 装入一个容量时长为10的光盘里,可以是1,2,3或者1,3,4等,但是不能2,1,3. 问最多 阅读全文
posted @ 2022-10-30 13:49 towboat 阅读(10) 评论(0) 推荐(0) 编辑
uva 442
摘要:矩阵连乘 用 栈 处理表达式 ((AB)C) #include <iostream> #include <cstdio> #include <string> #include <stack> using namespace std ; struct M{ int a,b; M(int a0=0,in 阅读全文
posted @ 2022-10-30 12:52 towboat 阅读(16) 评论(0) 推荐(0) 编辑
uva 10453
摘要:将字符串变为回文串最少需要几次操作(在任意位置插入字符),并输出变化后的回文串f[l][r] = f[l+1][r-1] // a[i]==a[j] =min(f[l+1][r],f[l][r-1]) #include <iostream> #include <cstring> using name 阅读全文
posted @ 2022-10-30 12:43 towboat 阅读(15) 评论(0) 推荐(0) 编辑
uva 10163
摘要:n个仓库,安排m个人看守,每个仓库只由一个人看守,每个人对应a[i] ,表示能量(薪水) 如果某个人看守k个仓库,每个仓库能量值 a[i]/k 求仓库能量最小值最大时,所支付薪水最少值 #include <iostream> #include <algorithm> #include <cstrin 阅读全文
posted @ 2022-10-30 00:10 towboat 阅读(20) 评论(0) 推荐(0) 编辑
luogu 3092
摘要:约翰到商场购物,他的钱包里有K(1 <= K <= 16)个硬币,面值的范围是1..100,000,000。 约翰想按顺序买 N个物品(1 <= N <= 100,000),第i个物品需要花费c(i)块钱,(1 <= c(i) <= 10,000)。 在依次进行的购买N个物品的过程中,约翰可以随时停 阅读全文
posted @ 2022-10-29 21:14 towboat 阅读(16) 评论(0) 推荐(0) 编辑
uva 1291
摘要:游戏者必须按照这个序列一次用某一只脚踩相应的踏板。在任何时候,两只脚不能在同一个踏板上,但可以同时在中心位置0。每一个时刻,HH必须移动他的一只脚去踩相应的箭头,另一只脚不能动。每跳完一个曲子,HH会计算他的总体力消耗。规定:从中心移动到任意一个箭头耗费2单位体力;从任何一个箭头到相邻的箭头耗费3单 阅读全文
posted @ 2022-10-29 01:12 towboat 阅读(15) 评论(0) 推荐(0) 编辑
uva 10564
摘要:和 数字金字塔 几乎一样 f[i[[j][s] s表示当前的和 #include<iostream> #include <cstring> #include <algorithm> using namespace std; const int N=90; #define int long long 阅读全文
posted @ 2022-10-28 22:55 towboat 阅读(16) 评论(0) 推荐(0) 编辑
uva 1366
摘要:一个方格图,每个格子上有 A 矿与 B 矿。A 矿只能向西运输,B 矿只能向北运输。即如果要采某个格子上的矿,那么运输路上的这种矿要全采 转移很明显了 f[i][j][0]=max(f[i-1][j][0],f[i-1][j][1])+s1[i][j]; f[i][j][1]=max(f[i][j- 阅读全文
posted @ 2022-10-28 19:50 towboat 阅读(15) 评论(0) 推荐(0) 编辑
uva 11795
摘要:题目意思还是有点绕的,想了好一会 大体上是一个状压dp(废话 f[j] ,当当前拥有武器集合为j 时,消灭所有怪物的方案数 像线性dp一样,但可以去掉一维 f[j]+=f[t] ,t= j^(1<<i ) 条件是 武器库j 能消灭 怪物i 这就要处理出 g[j] ,表示 武器库 j 能消灭的怪物集合 阅读全文
posted @ 2022-10-28 16:13 towboat 阅读(9) 评论(0) 推荐(0) 编辑
uva 1456
摘要:比如,手机可能位于 5 个区域中,概率分别为 0.3,0.05,0.1,0.3,0.25, 则一种方法是先同时访问 \{c1,c2,c3\},再同时访问 {c_4,c_5}, 访问区域数量的期望为 3*(0.3 + 0.05 + 0.1) + (3 + 2) *(0.3 + 0.25) = 4.1  阅读全文
posted @ 2022-10-28 14:01 towboat 阅读(15) 评论(0) 推荐(0) 编辑
uva11404
摘要:删去字符串S中的一些字符,使剩下的字符组成最长的回文串(顺序连接) 区间dp f[i][j] f[i][j] = f[i+1][j-1] i==j =min( f[i+1][j] ,f[i][j-1] ) #include<iostream> #include<string> #include <c 阅读全文
posted @ 2022-10-28 12:56 towboat 阅读(18) 评论(0) 推荐(0) 编辑
uva 11552
摘要:给你一个长度 k ,一个字符串 S(都为小写字母) ,保证 S 的长度为 k的整数倍。 将 S 按顺序分为 S/k 组,组内字符可以重新排列 问最少有几个块?(如 fff,ww ) 枚举开头元素j ,上一个组的末尾元素r f[i[j] = min{ f[i-1][r] - 1 +count[i] } 阅读全文
posted @ 2022-10-28 11:01 towboat 阅读(15) 评论(0) 推荐(0) 编辑
uva 10534
摘要:给一个序列A,求一个最长子序列,长度为2k+1 满足前k+1个数递增,后k个递减 LIS板子题,正反各求一次,枚举中间的交点 #include<iostream> #include<cstring> #include <algorithm> using namespace std; const in 阅读全文
posted @ 2022-10-28 10:06 towboat 阅读(14) 评论(0) 推荐(0) 编辑
uva 1424
摘要:给定一个长度为 n1​ ( n1​≤100 ) 的点的无向连通图和一个长度为 n 的序列 A ( n≤200 ) ,1<=A[i]<=n1 希望修改尽量少的数,使得序列的任意相邻两个数在图上是是相邻节点,或者相同 n<=100 ,直接暴力 枚举位置i,i-1 的值, 那么就可以转移 如果 k==j 阅读全文
posted @ 2022-10-28 09:31 towboat 阅读(14) 评论(0) 推荐(0) 编辑
uva 11584
摘要:给一个字符串,划分成最少的回文串 如aaadbccb > aa d bccb f[i] = miin{ f[j]+1 } j<i, 且 s[j...i]是回文串 #include <iostream> #include <cstring> using namespace std ; const in 阅读全文
posted @ 2022-10-27 23:32 towboat 阅读(14) 评论(0) 推荐(0) 编辑
uva 1169
摘要:地图上有n个点(x,y),机器人从(0,0) 出发到每个点捡垃圾(w[i]) ,承载最大重量为m 在每个点都可以返回(0,0)点放置垃圾 最短路程? n<1e5,m<100 看完范围只能设 f[i] ,考虑前i个点,返回原地所走的最短路程, d[i] = min{ d[j] + dis0(j+1) 阅读全文
posted @ 2022-10-27 22:22 towboat 阅读(17) 评论(0) 推荐(0) 编辑
uva 10891
摘要:A,B两人从序列两端轮流取数,每次可以取多个(甚至取完) 分数为所取数字的和,假设两人足够聪明,求得分差 f[i][j] 区间[i,j] ,先手取得最大得分 转移到取完后对方的序列 f[i][j] = s[i][j] - min{ f[i][k] , f[k2][j] } #include <ios 阅读全文
posted @ 2022-10-27 21:24 towboat 阅读(9) 评论(0) 推荐(0) 编辑
树状数组的板子
摘要:该数据结构可以维护序列的前缀和 1. 单点修改,求区间和 #include <iostream> using namespace std; const int N=5e5+2; int n,tr[N]; int lowbit(int x){ return x&-x; } void add(int x 阅读全文
posted @ 2022-10-27 19:32 towboat 阅读(21) 评论(0) 推荐(0) 编辑
pingpong uva1428
摘要:题目 求 三元组(i,j,k), i<j<k, 满足 a[i]<a[j]<a[k] 或者 a[i]>a[j]>a[k],有多少组?(a[i] <=1e5) 枚举 j , 考虑 a[i]<a[j] 有多少 i 满足这个条件 c[j] 正反求出 c[ i ] ,d[ i ] ans= c[i]*(n-i 阅读全文
posted @ 2022-10-27 19:20 towboat 阅读(4) 评论(0) 推荐(0) 编辑
st表板子
摘要:const int N=1e5+2; int st[N][20],n,a[N]; void init(){ int i,j; for(i=1;i<=n;i++) st[i][0]=a[i]; for(j=1;j<20;j++) for(i=1;i+(1<<j)-1<=n;i++){ st[i][j] 阅读全文
posted @ 2022-10-27 19:18 towboat 阅读(20) 评论(0) 推荐(0) 编辑
Frequent values uva11235
摘要:给一个非降序的排列{a},多次询问区间 (l,r) 中出现次数最大的值,输出这个次数 比如 1 2 6 6 8 8 8 10 23 相同的数据靠在一起,我们将相同数据组成一块(要处理出这个块的信息,比如左右端点 先查询中间的块的最大值(比如用st表) ,然后和两边的答案比较一下 #include < 阅读全文
posted @ 2022-10-27 19:00 towboat 阅读(12) 评论(0) 推荐(0) 编辑
线段树板子
摘要:有2种方式,都是用的lazy标记,但具体用法不同 1.区间加值 2.求区间和 https://www.luogu.com.cn/record/89949709 3.求区间最大值 https://www.luogu.com.cn/record/100443383 struct Tree{ int v; 阅读全文
posted @ 2022-10-27 18:55 towboat 阅读(24) 评论(0) 推荐(0) 编辑
一本通1549
摘要:给定一个正整数数列 a1,a2,a3,....a[n],每一个数都在 0∼p–1之间。可以对这列数进行两种操作: 添加操作:向序列后添加一个数,序列长度变成 n+1 询问操作:询问这个序列中最后 m个数中最大的数是多少。 程序运行的最开始,整数序列为空。写一个程序,读入操作的序列,并输出询问操作的答 阅读全文
posted @ 2022-10-27 18:52 towboat 阅读(23) 评论(0) 推荐(0) 编辑
滑动窗口问题
摘要:luogu 1886 有一个长为 n 的序列 a,以及一个大小为 k 的窗口。现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值。 单调队列,顾名思义 假设我们要维护一个单调递增的序列(不一定连续), 当遇到一个数 a[i] , 从 i-1 开始往前剔除元素x(当 a 阅读全文
posted @ 2022-10-27 18:46 towboat 阅读(23) 评论(0) 推荐(0) 编辑
luogu 1908 逆序对板子
摘要:逆序对的本质是二维偏序 给第一维排序(输入时已排好),统计 y(k)>=y(i) k<i 的个数 用树状数组维护 y 值 前缀和,需要的时候直接查询 该题需要离散化这个y ,再作为树状数组的下标 #include <iostream> #include <algorithm> using names 阅读全文
posted @ 2022-10-27 18:43 towboat 阅读(25) 评论(0) 推荐(0) 编辑
uva 1401
摘要:给一个串和一个字典(一些字符串) 将这个串分解为字典单词的连接(如 abcd = ab+cd =a+bcd ) 问有多少方案 线性dp 枚举位置 i f[i] += f[j] i<j , string(i,j) 为字典单词 直接枚举 j 和单词 明显超时 用到字典树,从 位置 i 开始在字典树上找单 阅读全文
posted @ 2022-10-27 18:32 towboat 阅读(18) 评论(0) 推荐(0) 编辑
luogu 4588
摘要:给xx这个数进行操作 1 m:将 xx 变为 x,并输出 x %mod 2 pos:将 xx 变为 xx 除以第 pos 次操作所乘的数(保证第 pos 次操作一定为类型 1,对于每一个类型 1 的操作至多会被除一次), 并输出 xx%mod 以修改次数为下标建立线段树,每个节点存对应区间元素的乘积 阅读全文
posted @ 2022-10-27 18:31 towboat 阅读(15) 评论(0) 推荐(0) 编辑
uva 10635
摘要:两个数组a,b,首元素都为1,a[i] b[i]<=K^2 求最长公共子序列的长度 暴力LCS会T,但注意 两个序列的元素都 <=K^2 对b[i] 找到 a[j] 配对(不存在为0) ,构造一个新序列,变为求LIS #include <iostream> #include <cstring> #i 阅读全文
posted @ 2022-10-27 17:13 towboat 阅读(15) 评论(0) 推荐(0) 编辑
一本通1282 二维前缀和
摘要:找最大子矩阵 数据水 O(n^4) 枚举矩形 + O(1) 求和 可以过 那么主要是写下二维前缀和 #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int inf=1<<30 阅读全文
posted @ 2022-10-26 21:36 towboat 阅读(30) 评论(0) 推荐(0) 编辑
一本通 1266
摘要:总公司拥有高效设备M台,准备分给下属的N个分公司。各分公司若获得这些设备,可以为国家提供一定的盈利。问:如何分配这M台设备才能使国家得到的盈利最大?求出最大盈利值。其中M≤15,N≤10。分配原则:每个公司有权获得任意数目的设备,但总台数不超过设备数M 虽然是水题,恰巧写一下这种类似背包输出具体方案 阅读全文
posted @ 2022-10-26 21:26 towboat 阅读(5) 评论(0) 推荐(0) 编辑
uva 1121
摘要:序列 {a} ,求最短子序列,且S>=K (S为序列元素的和)a[i]>=0. 暴力如下O(n^2) if(a[i]-a[j]>=K) ans=min(ans,i-j+1) i<j 变形一下 a[j]<=a[j]-K , 我们现在要找最大的这样的 j 注意a[i]>=0 s[i] 前缀和数组是单调序 阅读全文
posted @ 2022-10-26 20:09 towboat 阅读(9) 评论(0) 推荐(0) 编辑
uva 11549
摘要:用缓冲流保存字符串 #include <iostream> #include <string> #include <sstream> #include <set> using namespace std; int n; void upd(int &t){ stringstream ss; ss<<( 阅读全文
posted @ 2022-10-26 17:48 towboat 阅读(15) 评论(0) 推荐(0) 编辑
uva 11078
摘要:shui题 #include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int N=1e5+5; int a[N]; int n,m; void sol 阅读全文
posted @ 2022-10-26 16:54 towboat 阅读(4) 评论(0) 推荐(0) 编辑
uva 12097
摘要:有F+1个人来分N个圆形派,每个人得到的必须是一整块派(比如一个圆的1/5) , 而不是几块拼在一起。派的面积要相同。 求每个人最多得到多大面积的派(不必是圆形) 二分答案 假设为x 一个圆 分为 S/x ,算出能划出几块,和总人数比较 #include <iostream> #include <c 阅读全文
posted @ 2022-10-26 16:18 towboat 阅读(6) 评论(0) 推荐(0) 编辑
uva 12124
摘要:n个物品(属性有种类,价值,体积) 每个种类的物品挑一个,装入背包(V) , 体积不超V 问最小价值的物品最大是多少? 二分答案,即这个最小价值md 检验: 贪心,只考虑 V[i] >=md 的物品,每个种类挑体积最小的 看能否满足条件 #include <iostream> #include <c 阅读全文
posted @ 2022-10-26 15:45 towboat 阅读(14) 评论(0) 推荐(0) 编辑
uva11384
摘要:对1 , 2, ,3, ...n 这个序列操作最少的次数,序列元素都为0 又到了手玩样例环节 f(n) =f (n/2) +1 int m; int f(int x){ return x==1?x:f(x/2)+1; } signed main(){ while(cin>>m) cout<<f(m) 阅读全文
posted @ 2022-10-26 14:51 towboat 阅读(8) 评论(0) 推荐(0) 编辑
cf 1742D
摘要:a[i]<=1000 !!!! #include <iostream> #include <cmath> #include <cstring> using namespace std; int n,b[1003]; int gcd(int x,int y){ return y==0?x:gcd(y, 阅读全文
posted @ 2022-10-26 11:43 towboat 阅读(8) 评论(0) 推荐(0) 编辑
牛客 股票买卖的最佳时机
摘要:已知每支股票的价格序列 a , 进行若干次买卖( 一次买卖的收益a[j] - a[i] ) 求最大收益 f[i][0/1] #include <iostream> #include <vector> #include <cstring> using namespace std; const int 阅读全文
posted @ 2022-10-26 10:59 towboat 阅读(16) 评论(0) 推荐(0) 编辑
网络最大流 板子
摘要:残量网络: 由 剩余容量边和反向平衡流量 的边构成 dinic算法(省去了建图与s,t) 复杂度 O(n^2 *m) const int N =1e6+4, M =5*N ; const int inf =1e15+7; int all=1,hd[N],go[M],w[M],nxt[M]; int 阅读全文
posted @ 2022-10-25 23:31 towboat 阅读(20) 评论(0) 推荐(0) 编辑
uva 247
摘要:floy 找圈 #include <iostream> #include <vector> #include <map> #include <cstring> using namespace std; const int N=300; int a[N][N],vis[N],n,m; int tot; 阅读全文
posted @ 2022-10-25 22:53 towboat 阅读(20) 评论(0) 推荐(0) 编辑
uva 1395
摘要:求图上苗条度(最大边 - 最小边) 最小的生成树 像kruskal 一样,给边排序,枚举L,R 区间,更新答案 #include <iostream> #include <cstring> #include <algorithm> using namespace std ; const int M= 阅读全文
posted @ 2022-10-25 21:20 towboat 阅读(12) 评论(0) 推荐(0) 编辑
一本通 1479 AC自动机板子
摘要:kmp+字典树 #include <iostream> #include <cstring> #include <queue> using namespace std ; const int N=1e4+2,M=1e6+2; char s[M]; int val[N]; int ch[N][30], 阅读全文
posted @ 2022-10-25 18:22 towboat 阅读(18) 评论(0) 推荐(0) 编辑
一本通 1466 Power Strings
摘要:找字符串的最短循环节 1. kmp #include <bits/stdc++.h> using namespace std ; const int N=1e6+1; char a[N]; int n,p[N]; void init(){ int i,j=0; for(i=1;i<n;i++){ w 阅读全文
posted @ 2022-10-25 13:47 towboat 阅读(22) 评论(0) 推荐(0) 编辑
一本通 1467
摘要:一个字符串,它是由某个字符串不断自我连接形成的。但是这个字符串是不确定的,现在只想知道它的最短长度是多少。 #include <iostream> using namespace std ; const int N=1e6+1; char a[N]; int n,p[N]; void init(){ 阅读全文
posted @ 2022-10-25 13:44 towboat 阅读(17) 评论(0) 推荐(0) 编辑
kmp算法
摘要:关于字符串匹配问题 比如A,B串,现在要在A中找B 扫描A串,并更新能匹配到B的什么位置 关于kmp算法如何工作,有经典说法 神犇解说 摘选 我们用两个指针i和j分别表示,A[i-j+ 1..i]与B[1..j]完全相等。也就是说,i是不断增加的,随着i的增加j相应地变化,且j满足以A[i]结尾的长 阅读全文
posted @ 2022-10-25 00:52 towboat 阅读(16) 评论(0) 推荐(0) 编辑
uva 1401 字典树模板
摘要:给一个串和一个字典(一些字符串) 将这个串分解为字典单词的连接(如 abcd = ab+cd =a+bcd ) 问有多少方案 线性dp 枚举位置 i f[i] += f[j] i<j , string(i,j) 为字典单词 直接枚举 j 和单词 明显超时 用到字典树,从 位置 i 开始在字典树上找单 阅读全文
posted @ 2022-10-24 18:49 towboat 阅读(19) 评论(0) 推荐(0) 编辑
cf1739c
摘要:A,B 打牌(牌的数量为偶数), 计算A赢 B赢 平局的方案数 如果A赢 1.A获得最大的牌, 2.A没有最大的牌,但如果有 n-1 的牌,逼B交n的牌,也可能赢, >>>>> f[n][0]= c(n-1,n/2-1) +f[n-2][1] #include <iostream> using na 阅读全文
posted @ 2022-10-24 11:20 towboat 阅读(10) 评论(0) 推荐(0) 编辑
luogu 2344
摘要:给一个序列划分为若干组,每组的和 S>=0, 问方案数 首先是暴力dp for(i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]+a[i]; f[0]=1; for(i=1;i<=n;i++) for(j=0;j<i;j++) if(s[i]>=s[j]) f[i]+=f[j] 阅读全文
posted @ 2022-10-23 23:42 towboat 阅读(10) 评论(0) 推荐(0) 编辑
luogu 1908 逆序对
摘要:逆序对的本质是二维偏序 给第一维排序(输入时已排好), 统计 y(k)>=y(i) k<i (或者 y(k)<=y(i) ,k>i ) 用树状数组维护 y 值 前缀和 该题需要离散化这个y ,再作为树状数组的下标 第一种 y(k)<=y(i) ,k>i #include <iostream> #in 阅读全文
posted @ 2022-10-23 22:25 towboat 阅读(15) 评论(0) 推荐(0) 编辑
luogu 3004
摘要:小 A 和小 B 在玩游戏。 初始时,有 nn 个硬币被摆成了一行,从左至右数第 ii 个硬币的价值为 c_ici​。 小 A 和小 B 每人一回合,在一个人的回合中,他可以选择当前硬币序列最左侧或者最右侧的硬币,并将他从序列中取出,将其价值累加到自己获得的累计价值中,然后进行另一个人的回合。当硬币 阅读全文
posted @ 2022-10-23 20:11 towboat 阅读(15) 评论(0) 推荐(0) 编辑
luogu 2592
摘要:n个男生,m个女生排成一排,要求任意子段 中男女生的个数差 <=K 方案数? f[i][j][k][l] 目前i个男生,j个女生,个数差值为 k 和 l 转移很明显, 但最好用刷表法 #include <iostream> #include <cstring> #include <cmath> us 阅读全文
posted @ 2022-10-23 17:26 towboat 阅读(18) 评论(0) 推荐(0) 编辑
luogu 1336
摘要:#include <iostream> #include <cstring> #include <cmath> using namespace std ; const int N=203; #define int long long int a[N],b[N],n,m,f[N][2002]; int 阅读全文
posted @ 2022-10-23 14:20 towboat 阅读(5) 评论(0) 推荐(0) 编辑
luogu 4909
摘要:科罗拉多州的山脉是二维平面上的一条折线。这条折线由 NN 个端点,N−1N−1 段线段组成,第 ii 个端点的横坐标就是 ii,纵坐标是 H_iHi​,纵坐标代表高度,也可以称为海拔。 罗恩打算为奶牛建造一个滑雪场,为此要在山脉上规划一条缆车线路。缆线也是一条折线,由若干段缆绳组成,起点在山脉的第一 阅读全文
posted @ 2022-10-23 13:32 towboat 阅读(10) 评论(0) 推荐(0) 编辑
luogu 4084
摘要:给树的点染色,颜色有3种,相邻的点颜色不同 某些点已经染色 方案数? #include <bits/stdc++.h> using namespace std ; const int N=1e5+2,M=5*N; #define int long long const int mod=1e9+7; 阅读全文
posted @ 2022-10-23 11:40 towboat 阅读(12) 评论(0) 推荐(0) 编辑
luogu 1156
摘要:奶牛从井(H) 里往上爬,初始能量10, 有n个物品,可以用来堆叠(h[i]) 或者补充能量( w[i] ), 出现的时刻tm[i] 奶牛逃出去最少花费时间? 状态 f[i][j] 前i个物品, 此时高度为j 时 ,最大的能量 【因为高度范围明显(划掉 转移方程 f[i][j] = max( f[i 阅读全文
posted @ 2022-10-23 10:52 towboat 阅读(11) 评论(0) 推荐(0) 编辑
luogu 1282
摘要:对每个i ,从 a[i] b[i] 选一个 若选择 a[i] ,不贡献答案; 否则答案+1 在 sum{ a } -sum{ b } 最小的前提下,求出最小的答案 背包 #include <iostream> #include <algorithm> #include <cstring> using 阅读全文
posted @ 2022-10-23 00:24 towboat 阅读(15) 评论(0) 推荐(0) 编辑
luogu 2389
摘要:对序列{a} ,选择m个连续段,求总和最大 O(n^3) const int N=1e3; int a[N],s[N],n,m,f[N][N]; int sum(int i,int j){ return s[j]-s[i-1]; } void solve(){ int i,j,k; for(i=1; 阅读全文
posted @ 2022-10-22 21:56 towboat 阅读(21) 评论(0) 推荐(0) 编辑
luogu 2854
摘要:n条线段( 起点,终点,价值,费用) ,选择一些来覆盖 [0,L],注意所选线段不能相交 使价值之和最大? 背包题,而且背包体积要刚好用完 状态第一维放当前的位置(如果放线段编号,emmm好像没法做 f[a[i].y][j]=max(f[a[i].y][j],f[a[i].x][j-a[i].w]+ 阅读全文
posted @ 2022-10-22 16:55 towboat 阅读(14) 评论(0) 推荐(0) 编辑
luogu 1280
摘要:f[i] 对于某个区间起点,状态转移到终点,要反过来枚举 i 方程不难想,两种情况 f[i] =max{ f[i+len[j] ] } f[i]= f[i+1]+1 #include <iostream> #include <algorithm> #include <cmath> using nam 阅读全文
posted @ 2022-10-22 13:57 towboat 阅读(13) 评论(0) 推荐(0) 编辑
luogu 2426
摘要:很水的区间dp #include <iostream> #include <cstring> #include <cmath> using namespace std ; const int N=502; int n,a[N],f[N][N]; int func(int l,int r){ if(l 阅读全文
posted @ 2022-10-22 12:12 towboat 阅读(6) 评论(0) 推荐(0) 编辑
luogu 5020
摘要:两个货币系统 (n,a)(n,a) 和 (m,b)(m,b) 是等价的,当且仅当对于任意非负整数 xx,它要么均可以被两个货币系统表出,要么不能被其中任何一个表出。 现在网友们打算简化一下货币系统。他们希望找到一个货币系统 (m,b)(m,b),满足 (m,b)(m,b) 与原来的货币系统 (n,a 阅读全文
posted @ 2022-10-21 21:37 towboat 阅读(14) 评论(0) 推荐(0) 编辑
luogu 1107
摘要:有n个高度都为h的树(b[i]) ,树上的一些高度处有若干果实(比如b[i][h]==3) ,猫从任意的树顶部出发,可以 1.跳到任意其他的树上,高度将下降D 2.向下滑1个单位 问最多获得多少果实? 明显的dp 暴力程序 O(n^3) #include <iostream> #include <a 阅读全文
posted @ 2022-10-21 20:42 towboat 阅读(16) 评论(0) 推荐(0) 编辑
luogu 2513 逆序对数列
摘要:对于1~n的整数组成的的排列,其中逆序对数为K的排列有几种 比如n=4,K=1时 下列3个数列逆序对数都为1, 1 2 4 3 ;1 3 2 4 ;2 1 3 4; f[i][j] 表示 1~i 的整数组成排列, 逆序对数为 j ,的排列个数 将第i个数字插入前i个位置中 ,可能产生 0~i-1 个 阅读全文
posted @ 2022-10-21 14:47 towboat 阅读(17) 评论(0) 推荐(0) 编辑
luogu 1137
摘要:拓扑排序的过程很好描述: 每次访问入度=0 的所有点,删去,而且及时更新入度 在经过拓扑排序的图上求DAG最长路 #include <iostream> #include <queue> using namespace std ; const int N=1e6+3,M=2*N; int n,m; 阅读全文
posted @ 2022-10-20 21:33 towboat 阅读(11) 评论(0) 推荐(0) 编辑
存图
摘要:int nxt[M],go[M],hd[N],all; void add(int x,int y){ go[++all]=y,nxt[all]=hd[x]; hd[x]=all; } 阅读全文
posted @ 2022-10-20 21:22 towboat 阅读(19) 评论(0) 推荐(0) 编辑
cf543A
摘要:翻译下题目: n个物品,每种物品有无限个,物品体积,现在一共取m个物品,且物品总体积不超V 问方案个数 纯粹的背包dp,没什么说的 #include <iostream> #include <cstring> using namespace std; const int N=503; int mod 阅读全文
posted @ 2022-10-20 20:08 towboat 阅读(20) 评论(0) 推荐(0) 编辑
SP283 NAPTIME-Naptime
摘要:一个环上有n个点,价值 a[i],现在要选择m个点, 其中连续段的第一个元素的价值不算,求总和最大? 先考虑一条链 f[i][j][0/1] ,j 是目前选择了的点的个数, 0/1 当前点i 是否选择 状态转移: f[i][j][0]=max(f[i-1][j][0],f[i-1][j][1]) f 阅读全文
posted @ 2022-10-20 16:56 towboat 阅读(14) 评论(0) 推荐(0) 编辑
luogu 1351
摘要:水题 这里记录个步骤 对某节点x,其子节点为y 求 a[y1]*(a[y2]+a[y3]+ ... +a[yn]) + a[y2]*(a[y1]+a[y3]+...a[yn]) + .... + a[yn]*(a[y1]+a[y2]+...+a[y(n-1)] ) 观察一下,很容易推出 answer 阅读全文
posted @ 2022-10-19 21:58 towboat 阅读(20) 评论(0) 推荐(0) 编辑
最长单调不增子序列
摘要:普通的dp写法 f[i] = max{ f[j] +1 } j<i &&a[i]<=a[j] 复杂度 O(n^2) 单调队列写法 O(nlogn) int n,a[N],f[N],st[N],len; int cmp(int x,int y){ return x>y; } void solve(){ 阅读全文
posted @ 2022-10-19 19:34 towboat 阅读(31) 评论(0) 推荐(0) 编辑
luogu 1586
摘要:四方定理是众所周知的:任意一个正整数n,可以分解为不超过四个整数的平方和 给定的正整数n,统计它能分解的方案总数。注意:25=4^2+3^2 与 3^2+4^2 相同 背包,把每个平方数作为一个物品 直接用背包会重复累加,此时要利用这个定理,f[4][j] #include <iostream> # 阅读全文
posted @ 2022-10-19 16:30 towboat 阅读(14) 评论(0) 推荐(0) 编辑
luogu 1077
摘要:一些不同类型的物品,每种物品有可取个数的上限( a[i] ) 从中挑m个,求方案个数 这是背包问题? 考虑前 i 种物品,f[i][j] 表示方案个数, j 表示第i个物品取多少 f[i][j]+= f[i-1][j-k] f[0][0]=1 #include <iostream> using na 阅读全文
posted @ 2022-10-19 15:06 towboat 阅读(9) 评论(0) 推荐(0) 编辑
luogu 1057
摘要:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个同学可以把球传给自己左右的两个同学中的一个(左右任意),当老师再次吹哨子时,传球停止,此时,拿着球没有传出去的那个同学就是败者,要给大家表演一个节目。 有多少种不同的传球方法可以使得从小蛮手里开始传的球,传了m次以后,又 阅读全文
posted @ 2022-10-19 13:32 towboat 阅读(6) 评论(0) 推荐(0) 编辑
cf414b
摘要:1~M 挑数字(可重复), 能组成多少长度为n的合法序列? ( n,k =2000 合法序列: a[i] %a[i-1]==0 f[i][j] += f[i-1][k] , j%k==0 #include <iostream> using namespace std; const int N=200 阅读全文
posted @ 2022-10-19 12:26 towboat 阅读(17) 评论(0) 推荐(0) 编辑
luogu 1018
摘要:数字串分割为m个部分,求乘积最大? 例如有一个数字串:312, 当 N=3,K=1 时会有以下两种分法: 3 * 12 31*2 这时,符合题目要求的结果是: 31 *2 转移方程 在注释里,不解释 以下代码只有80分,AC需要换成高精度(笔者大概是没学过的 #include <iostream> 阅读全文
posted @ 2022-10-18 21:18 towboat 阅读(13) 评论(0) 推荐(0) 编辑
luogu 1049
摘要:有一个箱子容量为 VV,同时有 nn 个物品,每个物品有一个体积。 现在从 nn 个物品中,任取若干个装入箱内(也可以不取),使箱子的剩余空间最小。输出这个最小值。 #include <iostream> #include <vector> #include <cstring> using name 阅读全文
posted @ 2022-10-18 20:33 towboat 阅读(10) 评论(0) 推荐(0) 编辑
状态压缩dp的两个经典问题
摘要:这里的图染色问题 : 用最少的颜色给一个无向图的点染色,且相邻节点颜色不同 f[s] = min{ f[s-s2]+1 } ,s2为s的子集 值得注意集合S 的子集如何枚举? for(j=S; j ;j=(j-1)&S) #include <iostream> #include <vector> u 阅读全文
posted @ 2022-10-18 18:49 towboat 阅读(15) 评论(0) 推荐(0) 编辑
Perfect Service UVA - 1218
摘要:树上的点可以涂成黑色或白色,求最少的黑色点,使得任意白点只和一个黑点相连 白点只和一个黑点相连,所以对于节点x, 不仅考虑 x ,son[x] 的情况,还有 x,father[x] f[x][3] 黑点个数 0: x 为 黑点 1:x为白点,且father[x] 为黑点 2:x 白点,father[ 阅读全文
posted @ 2022-10-18 16:36 towboat 阅读(12) 评论(0) 推荐(0) 编辑
3个经典树上问题
摘要:1.树的最大独立集 任选一个点作为根,有了以下得状态 f[i][0/1] f[i][0] += max(f[y][0], f[y][1] f[i][1] += f[i][0] #include <iostream> #include <vector> using namespace std; con 阅读全文
posted @ 2022-10-18 15:43 towboat 阅读(26) 评论(0) 推荐(0) 编辑
uva 10003
摘要:#include <iostream> #include <cstring> using namespace std ; const int N=60,inf=1<<30; int n,L,a[N],vis[N][N],f[N][N]; int dp(int l,int r){ if(l>=r-1) 阅读全文
posted @ 2022-10-18 15:08 towboat 阅读(11) 评论(0) 推荐(0) 编辑
uva 1025
摘要:f[i][j] 在 i 车站,当前经过的时间 j ,所需最小等待时间 f[i][j]= f[i][j+1] +1; //等待 f[i][j]= min{ f[i-1][j+t[j]] } //向右 f[i][j] =min{ f[i+1][j+t[j-1]] } // 向左 #include <io 阅读全文
posted @ 2022-10-18 14:18 towboat 阅读(12) 评论(0) 推荐(0) 编辑
luogu 3143
摘要:题目 在序列中找两个不相交的子序列, 子序列满足 max_number - min_number <=k 动态规划,还需要双指针 正反总共扫两遍(f 和 g) 设 f[i] 为[1,i] 满足要求的序列的最大长度 f[i] = max( f[i-1] , i-j+1) #include <iostr 阅读全文
posted @ 2022-10-17 19:08 towboat 阅读(8) 评论(0) 推荐(0) 编辑
滑动窗口 问题
摘要:luogu 1886 有一个长为 nn 的序列 aa,以及一个大小为 kk 的窗口。现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值。 单调队列,顾名思义 假设我们要维护一个单调递增的序列(不一定连续), 当遇到一个数 a[i] , 从 i-1 开始往前剔除元素x( 阅读全文
posted @ 2022-10-17 16:20 towboat 阅读(20) 评论(0) 推荐(0) 编辑
uva11572
摘要:对序列{a} ,找一个最长的连续子序列 ,其中没有相同的数字 双指针 容易想到 O(n^2) 的算法,枚举i ,再枚举一个j 尝试向后延伸 注意到 j到达终点(无法延伸) 时, 朴素算法此时执行 i++,j=i 但其实不必,当 [i,j] 可行时,[i+1,j] 也是可行的,所以此时j继续增大即可, 阅读全文
posted @ 2022-10-17 14:36 towboat 阅读(19) 评论(0) 推荐(0) 编辑
cf1736c1
摘要:对于序列{a} 求其连续子序列{b} 满足 b[i]>=i,有几个? 比如 1 4 6 7 3 , [3],[1,4] [6,7,3]都是合法的 双指针的题 #include <iostream> #include <algorithm> using namespace std; const int 阅读全文
posted @ 2022-10-17 14:27 towboat 阅读(6) 评论(0) 推荐(0) 编辑
二分查找与二分答案
摘要:关于二分查找这里记录一下两个函数,即lower_bound(l,r) , upper_bound(l,r) ,分别是求: 1. 大于等于x的第一个位置 2.大于x的第一个位置 //lower_bound() int l_bound(int x,int y,int v){ while(x<y){ in 阅读全文
posted @ 2022-10-17 12:43 towboat 阅读(24) 评论(0) 推荐(0) 编辑
最大子段和
摘要:(luogu P1115) 方法1 维护前缀和s[i] ,所求的最大和 为 max{ s[j] - s[i] } , i<j 我们枚举j ,即s[j] 确定,此时只需要 s[i] 最小即可 ,于是维护这个最小值 #include <iostream> using namespace std ; co 阅读全文
posted @ 2022-10-15 17:34 towboat 阅读(11) 评论(0) 推荐(0) 编辑
st表 查询区间最值
摘要:const int N=1e5+2; int st[N][20],n,a[N]; void init(){ int i,j; for(i=1;i<=n;i++) st[i][0]=a[i]; for(j=1;j<20;j++) for(i=1;i+(1<<j)-1<=n;i++){ st[i][j] 阅读全文
posted @ 2022-10-15 09:01 towboat 阅读(16) 评论(0) 推荐(0) 编辑
树状数组的一些板子
摘要:该数据结构可以维护序列的前缀和 1. 单点修改,求区间和 #include <iostream> using namespace std; const int N=5e5+2; int n,tr[N]; int lowbit(int x){ return x&-x; } void add(int x 阅读全文
posted @ 2022-10-14 13:51 towboat 阅读(13) 评论(0) 推荐(0) 编辑
uva 1329
摘要:并查集路径压缩中,维护某节点到根节点的距离(依题意为abs(x-y)%1000) 即 d[i] +=d[father[i] ] #include <iostream> #include <algorithm> #include <cmath> using namespace std; const i 阅读全文
posted @ 2022-10-14 13:34 towboat 阅读(11) 评论(0) 推荐(0) 编辑
uva 1160
摘要:并查集判断图上是否有环 #include <iostream> #include <algorithm> using namespace std; const int N=1e5+4; int fa[N]; int find(int x){ return x==fa[x]?x:fa[x]=find( 阅读全文
posted @ 2022-10-14 13:05 towboat 阅读(5) 评论(0) 推荐(0) 编辑
cf826E
摘要:人跨台阶,每次能跨越的高度最大为D,给了每个台阶的高度,求最多走多高 解: 求一个数组里第一个x , a[x]>D ?处理一个前缀max ,然后查找 #include <iostream> #include <algorithm> using namespace std; const int N=2 阅读全文
posted @ 2022-10-14 08:31 towboat 阅读(15) 评论(0) 推荐(0) 编辑
cf#806G
摘要:题目 There are nn chests. The ii-th chest contains aiai coins. You need to open all nn chests in order from chest 11 to chest nn. There are two types of 阅读全文
posted @ 2022-10-13 17:02 towboat 阅读(11) 评论(0) 推荐(0) 编辑
递推组合数
摘要:const int M=1e3; const int N=2e3; int c[N][N]; void init(){ int i,j; c[1][1]=1; for(i=0;i<=M;i++) c[i][0]=1; for(i=2;i<=M;i++) for(j=1;j<=i;j++) c[i][ 阅读全文
posted @ 2022-10-13 11:16 towboat 阅读(20) 评论(0) 推荐(0) 编辑
奶牛和轿车 Cows and Cars uva 10491
摘要:全概率公式 #include <iostream> #include <cstring> #include <iomanip> using namespace std; int main(){ double a,b,c; while(cin>>a>>b>>c){ cout<<setprecision 阅读全文
posted @ 2022-10-13 10:53 towboat 阅读(7) 评论(0) 推荐(0) 编辑
同余线性方程组
摘要:求解 ax Ξb (mod n) 充要条件: ax-b= k*n 即 ax-ny = b 1. 用exgcd 可以求方程 ax-ny= gcd(a,n) 的一组解 即 x0 , y0, https://www.cnblogs.com/towboa/p/17001472.html 2. 可以得到原方程 阅读全文
posted @ 2022-10-12 23:53 towboat 阅读(19) 评论(0) 推荐(0) 编辑
幂取模
摘要:运用分治,复杂度logn typedef long long LL; LL mod; LL f(LL a,LL b){ if(b==1) return a; if(b==0) return 1; LL t=f(a,b/2); return b%2==0? t*t%mod : (((t*t)%mod) 阅读全文
posted @ 2022-10-12 23:31 towboat 阅读(12) 评论(0) 推荐(0) 编辑
筛质数
摘要:int b[N+2], pm[N+2],tot=0; void init(){ b[1]=1; for(int i=2;i<=N;i++){ if(b[i]) continue; pm[++tot]= i; for(int j=2;j*i<=N;j++) b[j*i]=1; } } const in 阅读全文
posted @ 2022-10-12 23:16 towboat 阅读(20) 评论(0) 推荐(0) 编辑
扩展欧几里得算法
摘要:算法求解了不定方程 ax+by=gcd(a,b) (1) 的一组解x0,y0 void gcd(int a,int b,int &d,int &x,int &y){ if(b==0){ d=a; x=1,y=0; return ; } gcd(b,a%b,d,y,x); y-=x*(a/b); } 阅读全文
posted @ 2022-10-12 23:05 towboat 阅读(18) 评论(0) 推荐(0) 编辑
cf820G
摘要:操作:从字符串a中扣除给定的子串b(如hebheof 和 he ,结果 --bheof或heb--of 问直到无法操作时,至少需要几次 #include<iostream> #include <vector> #include <cstring> using namespace std; const 阅读全文
posted @ 2022-10-12 20:31 towboat 阅读(21) 评论(0) 推荐(0) 编辑
cf815C
摘要:题意: 有n件商品,每件有价格c[i],优惠券d[i], 对于i>=2,使用di的条件为:xi的优惠券需要被使用,问初始金钱为b时 最多能买多少件商品? n<=5000 解答 树上背包 f[u][j][0/1] 表示某子树(u)有体积j(分配的物品数目) ,该物品是否选择,所需要的最小金钱 f[u] 阅读全文
posted @ 2022-10-10 17:54 towboat 阅读(20) 评论(0) 推荐(0) 编辑
知识 树上背包
摘要:例子: luogu <选课> 课程有依赖关系形成树状结构,每个节点有价值a[i], 若选择X节点 则必须选择其父节点,最多选m个节点 问能获得的最大价值 f[u][i][j] 结点u,可用体积为j(节点个数),考虑前i个子节点,能获得的最大价值 我们枚举第i个点分配的体积k f[u][i][j]= 阅读全文
posted @ 2022-10-10 16:31 towboat 阅读(15) 评论(0) 推荐(0) 编辑
cf1060E
摘要:题目 给出一棵树,每条边的长度为1 现在对于原图中每一对距离为2的点,连一条长度为1的边。 求 ,1<=i<j<=n 其中dist(i,j) 是两点的最短距离 解答 符号 [ ]为向上取整 考虑一对(i,j),每一步一定贪心地走长度为2的边(然后最后一步可能要走长度为1的边 则 dist(i,j)= 阅读全文
posted @ 2022-10-10 12:56 towboat 阅读(17) 评论(0) 推荐(0) 编辑
cf1153D
摘要:题目 (n=3e5 n个节点以1为根的一棵树,每个非叶子节点都有一个操作max或min(0表示min,1表示max),表示这个节点中的值应该分别等于其子节点中所有值的最大值或最小值。 假设树上有k个叶节点,你可以将每个叶节点填上[1,k]的数字,且每个数字只使用一次,求根节点的最大值 解答 思维题 阅读全文
posted @ 2022-10-10 09:46 towboat 阅读(15) 评论(0) 推荐(0) 编辑
cf791C
摘要:题目 sum{dis(i,j)} dis(i,j) 为两点的最短跳跃次数,(每次可以跳k条边) 解答 #include <iostream> #include <cstring> #include <vector> using namespace std; const int N=2e5+4; #d 阅读全文
posted @ 2022-10-09 22:47 towboat 阅读(16) 评论(0) 推荐(0) 编辑
CF922E
摘要:题目 n棵树,开始有W元,第i棵树上有num[i]只鸟,第i棵树上的一只鸟要花c[i]元,每走一棵树增加x元,每买一个鸟会让钱包容量增加b,问最多能买到几只鸟? 解答 线性dp,状态f[i][j] ,j是当前拥有鸟的个数 f[i][j] = max{f[i-1][j-k]+X-w[i-1]*k #i 阅读全文
posted @ 2022-10-09 10:49 towboat 阅读(22) 评论(3) 推荐(0) 编辑
cf118D
摘要:题目 现有A,B两种物品(各有n1和n2个) 组成一个排列(全部物品都用到), 且满足条件 : 不会出现连续k个物品 (对A物品 k=k1, B物品k=k2) 解答 线性dp,设f[i][j][k][0/1] 前i个物品,j个A,k个B,最后一个取A或B 枚举最后一个连续相同物品的区间即可 f[i] 阅读全文
posted @ 2022-10-08 17:52 towboat 阅读(6) 评论(0) 推荐(0) 编辑
cf455A
摘要:题目 序列{a} 操作: 删掉元素a[i] ,并同时删掉a[i]-1,a[i]+1 的元素 。 本次操作的收益为a[i] 问最大收益 解答 用一个桶b[i] 存a[i]的个数 f[i][1/0]表示前i个数,第i个数是否选 若选择了某个值 x, 产生收益 x*( x的个数) f[i][0]=max( 阅读全文
posted @ 2022-10-08 09:53 towboat 阅读(12) 评论(0) 推荐(0) 编辑
cf1731A
摘要:题目 略 简单的贪心 #include <iostream> #include <cstring> using namespace std; const int N=2003; int n,k,len; int c[30]; char s[N]; int main(){ int cas; cin>> 阅读全文
posted @ 2022-10-08 09:15 towboat 阅读(11) 评论(0) 推荐(0) 编辑
cf366c
摘要:题目 n个物品 有属性a[i],b[i] 选择若干物品,且有sum{a[i]}=sum{b[i]}*k, 问 sum{a[i]} 最大值 n<=100 解答 01背包, sum{a[i]} -sum{b[i]}*k==0, 展开写 (a[1]-b[1]*k) + (a[2]-b[2]*k) + .. 阅读全文
posted @ 2022-10-08 09:07 towboat 阅读(15) 评论(0) 推荐(0) 编辑
cf1312E
摘要:题目 对序列a 进行操作 对两个相等的相邻元素 ,合并为a[x]+1 问最后剩余序列的最小长度 区间dp,f[i][j]表示某区间的合成值,g[i][j]表示某区间最终的序列长度 那么直接开始区间dp的套路,考虑[i,j]分割为 [i,k],[k+1,j] 不合并时 应该取g[i][j]=min(g 阅读全文
posted @ 2022-10-07 19:47 towboat 阅读(17) 评论(0) 推荐(0) 编辑
cf189A
摘要:题目 整数n拆分为若干数字(a,b或c)的和,求序列最大长度 如 5=2+1+1 完全背包,但要求体积刚好用完 f[i][j] 表示最大个数 改下dp边界,f[0]=0,else f[i]= -inf #include <iostream> #include <cstring> using name 阅读全文
posted @ 2022-10-07 17:37 towboat 阅读(15) 评论(0) 推荐(0) 编辑
cf855B
摘要:题目 max{p·ai + q·aj + r·ak } 从n个元素里挑出3个求值,且每个元素可以选多次,简单的无穷背包 注意有负数 #include <iostream> #include <cstring> using namespace std; const int N=1e5+3; #defi 阅读全文
posted @ 2022-10-07 17:19 towboat 阅读(19) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示