摘要: 题目链接:Link Problem Solution 如果直接做的话,你会发现你需要计算浮点数的异或值。。。考虑到位运算的每一位是独立的,所以可以分开计算。。。 此时转移方程就变成了这个: \[f(u)=\text{u到n的期望值} \]\[f(n)=0 \]\[f(u)=\frac{1}{d} ( 阅读全文
posted @ 2019-10-07 09:15 happyZYM 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 暴力枚举边数,用传递闭包判断当前状态即可。 Code #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<cassert> using n 阅读全文
posted @ 2019-10-05 08:33 happyZYM 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 显然可以二分答案,然后计算需要报销多少条电缆,以此来判断接下来的二分区间。 Code #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include 阅读全文
posted @ 2019-10-05 08:04 happyZYM 阅读(136) 评论(2) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 令 $ f(u,i)= $ u为根节点的子树中,得i票的最小代价。 若有一个决策,代价为w,得v票,则 $ f(u,i)=min(f(u,i),f(u,i-v)+w) $ 不难发现,递归求取子树的解后,可将每个子树视为一个泛化物品,用分组背包求解 阅读全文
posted @ 2019-10-04 21:13 happyZYM 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 首先不难想出一个二维的dp,然后你会发现你被这玩意儿弄跪了: 1 10 9 1 1 9 1 10 1 10 8 9 二维dp的问题在于:已经积攒起来的方块只能随着分治的过程下放,没法积攒起来备用。 因此我们可以把维度增加一维,即: $ f(i,j 阅读全文
posted @ 2019-10-04 19:24 happyZYM 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 不难发现可以直接二进制化后,枚举每一位选什么,如果选择0则直接调用预处理过的答案。注意如“是否允许前导0”之类的细节即可。 Code #include<cstdio> #include<cstring> #include<algorithm> u 阅读全文
posted @ 2019-10-03 20:47 happyZYM 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 不难发现单个邮局管理的一定是连续的一段,且P=1的情况就是中位数,暴力dp即可。 Code #include<cstdio> #include<cstring> #include<algorithm> using namespace std; c 阅读全文
posted @ 2019-10-03 16:13 happyZYM 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 不难想出分7次dp的做法,此时转换后的问题就成了一个单调栈裸题。。。 Code #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const i 阅读全文
posted @ 2019-10-03 15:57 happyZYM 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 定义状态如下: $ f(i,j) $ = 第i天结束后,手中有j股的最大收益 初始化: $ f(i,j)=-\infty \quad f(0,0)=0 $ 不妨发现有如下选择: 什么都不做,此时 $ f(i,j)=f(i-1,j) $ 。 $ j 阅读全文
posted @ 2019-10-02 19:36 happyZYM 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 不难发现最瘦的塔一定是最高的。 将序列翻转后作如下定义: $ f(i) $ = 1~i的草搭成的最小宽度 $ g(i) $ = 1~i的草搭成的最大高度 $ s(i) $ = 1~i的草搭成的宽度的前缀和 则 \[\large f(i)= \mi 阅读全文
posted @ 2019-09-29 21:37 happyZYM 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 显然不难找到状态转移方程,关键是如何快速预处理出某一段区间的代价。 易证对于某个确定的区间,b值就是中位数。在用对顶堆维护时顺带维护当前堆里的元素和即可在 $ O(n^2 log n) $ 内预处理完(15000ms好评)。。。 Code //h 阅读全文
posted @ 2019-09-24 21:09 happyZYM 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 这题其实就是一道数位dp的板子题。。。但是我一开始想复杂了。。。莫名其妙WA了。。。拍几万组数据都找不到锅在哪儿。。。心肌梗塞的感觉。。。 坑点:a可能大于b Code #include<cstdio> #include<cstring> #in 阅读全文
posted @ 2019-09-20 20:00 happyZYM 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 显然,如果我们知道从每个地方跳下去会落到哪里,就可以很方便地dp了,于是我们可以用线段树维护区间赋值操作,先预处理出跳到哪里。 Code #include<cstdio> #include<cstring> #include<algorithm> 阅读全文
posted @ 2019-09-18 21:55 happyZYM 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 这题主要在于预处理出可能的决策以减少不必要的计算。 Code #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int mod=10 阅读全文
posted @ 2019-09-17 21:18 happyZYM 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Link Problem Solution 可以跑出直径的2个端点再来个树上lca 这题是经典的二次扫描+换根法,分向上和向下dp2次即可。 Code #include<cstdio> #include<cstring> #include<algorithm> #include<vecto 阅读全文
posted @ 2019-09-17 21:02 happyZYM 阅读(111) 评论(0) 推荐(0) 编辑