随笔 - 532  文章 - 0  评论 - 3  阅读 - 10867 

随笔分类 -  dp

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 阅读全文
posted @ 2023-02-20 17:09 towboat 阅读(9) 评论(0) 推荐(0) 编辑
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] 阅读全文
posted @ 2023-02-20 16:02 towboat 阅读(16) 评论(0) 推荐(0) 编辑
状压dp 记录
摘要:https://www.luogu.com.cn/problem/P1896 http://ybt.ssoier.cn:8088/problem_show.php?pid=1593 https://vjudge.net/problem/HDU-3091 https://zoj.pintia.cn/p 阅读全文
posted @ 2022-12-23 16:12 towboat 阅读(9) 评论(0) 推荐(0) 编辑
树上dp 记录
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1575 http://ybt.ssoier.cn:8088/problem_show.php?pid=1576 http://ybt.ssoier.cn:8088/problem_show.php?pid 阅读全文
posted @ 2022-12-23 00:19 towboat 阅读(10) 评论(0) 推荐(0) 编辑
区间dp 记录
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1569 http://ybt.ssoier.cn:8088/problem_show.php?pid=1570 http://ybt.ssoier.cn:8088/problem_show.php?pid 阅读全文
posted @ 2022-12-22 19:18 towboat 阅读(11) 评论(0) 推荐(0) 编辑
dp 记录
摘要:https://ac.nowcoder.com/acm/problem/21303 https://ac.nowcoder.com/acm/problem/21314 https://ac.nowcoder.com/acm/problem/21186 阅读全文
posted @ 2022-12-16 18:16 towboat 阅读(11) 评论(0) 推荐(0) 编辑
多重背包二进制优化
摘要:复杂度 n^2 * logn 类似倍增, 将 num[i] 拆为 1+2+4+ .... ,这样取物品i 时,可以一次多取一些 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const 阅读全文
posted @ 2022-12-07 15:44 towboat 阅读(23) 评论(0) 推荐(0) 编辑
acwing 280. 陪审团
摘要:第 i个人的得分分别记为 a[i] 和 b[i]m个人必须满足:辩方总分S(a) 和控方总分 S(b) 的差的绝对值最小如果选择方法不唯一,那么再从中选择辨控双方总分之和最大的方案。求最终的陪审团获得的辩方总分 D 控方总分 P, 以及陪审团人选的编号 吧这个绝对值的差的和作为状态 f[ i ] [ 阅读全文
posted @ 2022-12-03 18:50 towboat 阅读(17) 评论(0) 推荐(0) 编辑
275. 传纸条
摘要:#include <iostream> using namespace std ; const int N=51; int n,m,a[N][N],f[N][N][N][N]; int MAX(int a,int b,int c,int d){ if(a<b) a=b; if(c<d) c=d; i 阅读全文
posted @ 2022-12-03 13:29 towboat 阅读(27) 评论(0) 推荐(0) 编辑
274. 移动服务
摘要:#include "bits/stdc++.h" using namespace std; const int N=202; #define Min(x,y) x=min(x,y) int n,m,a[N][N],f[1002][N][N]; int p[1002]; void sov(){ int 阅读全文
posted @ 2022-12-03 12:50 towboat 阅读(84) 评论(0) 推荐(0) 编辑
acwing 273. 分级
摘要:#include "bits/stdc++.h" using namespace std; const int N=2e3+3; int n,a[N],b[N],f[N][N]; int A=1e9; void sov(){ int i,j,k; for(i=1;i<=n;i++)b[i]=a[i] 阅读全文
posted @ 2022-12-02 23:27 towboat 阅读(17) 评论(0) 推荐(0) 编辑
P2134 百日旅行
摘要:剩下 n天的假期,小明可以安排旅行的计划。 如果连续 xx 天旅游,小明需要花旅行费用 p*x*x 元;如果连续 x 天不旅游,小明吃饭,花费为 q*x 计算出他至少需要花费多少元。 需要斜率优化,这里先写下暴力,后面学了再补 #include<iostream> #include <algorit 阅读全文
posted @ 2022-11-10 21:15 towboat 阅读(15) 评论(0) 推荐(0) 编辑
acwing 529 宝藏
摘要:给一个图,选定一个点为起点,求一个生成树,代价和最小(跑一条长度为z的边的代价:z*d ,d是起点的深度) n<=12 对于一个状态S, 由S2,S-S2组成,其中S2的点深度为d +1 f[u][d][s] = f[i][d+1][s2] + f[u][d][s-s2] + a[u][i] * d 阅读全文
posted @ 2022-11-05 23:19 towboat 阅读(21) 评论(0) 推荐(0) 编辑
一本通 1593
摘要:农场主 John 新买了一块长方形的新牧场,m*n (1≤M≤12;1≤N≤12),John 打算在牧场上的某几格里种上美味的草 。 遗憾的是,有些土地相当贫瘠,不能用来种草。并且,John 不会选择两块相邻的土地,也就是说,没有哪两块草地有公共边。 如果不考虑草地的总块数,那么,一共有多少种种植方 阅读全文
posted @ 2022-11-05 19:01 towboat 阅读(18) 评论(0) 推荐(0) 编辑
数位dp例题
摘要:https://zhuanlan.zhihu.com/p/50791875 1. 某人命名了一种不降数,这种数字必须满足从左到右各位数字成小于等于的关系,如12245 问区间【l,r】内有多少个不降数。 #include <iostream> #include <vector> #include < 阅读全文
posted @ 2022-11-05 15:14 towboat 阅读(19) 评论(0) 推荐(0) 编辑
luogu 2607
摘要:题意和<没有上司的舞会> 一样,多了点东西:每颗树(总体为森林)上多一个环,问最大权值和 基环树,考虑把这种图去掉一条边,就变成树,然后dp 然后考虑这条去掉的边的影响: 两条边的端点x,y,不能都选 那么做法就是 取 f[x][0], f[y][0] 分别进行dp #include <iostre 阅读全文
posted @ 2022-11-04 11:41 towboat 阅读(16) 评论(0) 推荐(0) 编辑
一本通 1579
摘要:一棵有点权的树,选择一些点, 使得每个点至少满足下列中的一个: 1.已被选择 2.父亲被选择 3.子节点至少有一个被选择 求点权和最小值 f[x][0]=SUM{ min(f[y][1],f[y][2] } f[x][2] = SUM { min(f[y][0],f[y][1],f[y][2]) } 阅读全文
posted @ 2022-11-03 21:27 towboat 阅读(15) 评论(0) 推荐(0) 编辑
acwing298 围栏
摘要:有 NN 块木板从左到右排成一行,有 MM 个工匠对这些木板进行粉刷,每块木板至多被粉刷一次。 第 ii 个木匠要么不粉刷,要么粉刷包含木板 Si 的,长度不超过 Li 的连续的一段木板,每粉刷一块可以得到 Pi 的报酬。 如何安排能使工匠们获得的总报酬最多 #include <iostream> 阅读全文
posted @ 2022-11-02 18:42 towboat 阅读(11) 评论(0) 推荐(0) 编辑
1602:烽火传递
摘要:序列A,选择一些a[i] , 任意一个长度为m的区间内至少有一个所选的 问 sum{ a[i] } 的最小值 #include <iostream> #include <cstring> using namespace std; const int N=2e5+5; int a[N],n,m,f[N 阅读全文
posted @ 2022-11-02 08:52 towboat 阅读(27) 评论(0) 推荐(0) 编辑
一本通1603 绿色通道
摘要:有 n 道题目要抄,耗时a[i] 。用不超过 t分钟抄这个,每道题要么不写,要么抄完,。 下标连续的一些空题称为一个空题段,它的长度就是所包含的题目数。 现在,小 Y 想知道他在这 t 分钟内写哪些题,才能够尽量减轻马老师的怒火( 连续空题段的最大值 ) #include <iostream> #i 阅读全文
posted @ 2022-11-02 00:13 towboat 阅读(85) 评论(0) 推荐(0) 编辑

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