Yet Another Minimization Problem dp方程我们很容易能得出, f[ i ] = min(g[ j ] + w( j + 1, i )). 然后感觉就根本不能优化. 然后就滚去学决策单调啦. 然后就是个裸题, 分治一下就好啦, 注意用分治找决策点需要的条件是我们找出被决策点不能作为当前转移的决策点使用. 如果w( j + 1, i )能很方便求出就能用单调栈维护, 并且找出的被决策点能当作当前转移的决策点使用. 我怎么感觉用bfs应该跑莫队的时候应该比dfs快啊,…
题目链接  Yet Another Minimization Problem 题意  给定一个序列,现在要把这个序列分成k个连续的连续子序列.求每个连续子序列价值和的最小值. 设$f[i][j]$为前$i$个数分成$j$段的最优解 不难得出状态转移方程$f[i][j] = min(f[k][j - 1], calc(j + i, i))$ 该DP具有决策单调性 即若$f[i][j]$是从$f[x][j - 1]$转移到的,$f[i+1][j]$是从$f[y][j - 1]$转移到的,那么一定有$…
题意 给定一个序列 \(\{a_1, a_2, \cdots, a_n\}\),要把它分成恰好 \(k\) 个连续子序列. 每个连续子序列的费用是其中相同元素的对数,求所有划分中的费用之和的最小值. \(2 \le n \le 10^5, 2 \le k \le \min(n, 20), 1 \le a_i \le n\) 题解 \(k\) 比较小,可以先考虑一个暴力 \(dp\) . 令 \(dp_{k, i}\) 为前 \(i\) 个数划分成 \(k\) 段所需要的最小花费. 那么转移如下…
LINK 题目大意 给你一个序列分成k段 每一段的代价是满足\((a_i=a_j)\)的无序数对\((i,j)\)的个数 求最小的代价 思路 首先有一个暴力dp的思路是\(dp_{i,k}=min(dp_{j,k}+calc(j+1,i))\) 然后看看怎么优化 证明一下这个DP的决策单调性: trz说可以冥想一下是对的就可以 所以我就不证了 (其实就是决策点向左移动一定不会更优) 然后就分治记录当前的处理区间和决策区间就可以啦 //Author: dream_maker #include<bi…
Description 给出一个长度为 \(n\) 的序列,你需要将它分为 \(k\) 段,使得每一段的价值和最小,每一段的价值是这一段内相同的数的个数 题面 Solution 容易想到设 \(f[i][j]\) 表示前 \(i\) 个数分成 \(j\) 段的最小代价 \(f[i][j]=min(f[k][j-1]+w(k+1,i))\) 这个\(DP\)有决策单调性,可以分治优化 设 \(solve(l,r,L,R)\) 表示用区间 \([L,R]\) 内的决策去更新 \([l,r]\) 的函…
原题链接 题目大意是有N个数,分成K段,每一段的花费是这个数里相同的数的数对个数,要求花费最小 如果只是区间里相同数对个数的话,莫队就够了 而这里是!边单调性优化边莫队(只是类似莫队)!而移动的次数和分治的复杂度是一样的! 这个时候就不能用单调栈+二分了,得用分治 分治的方法就是\(Solve(l,r,ql,qr)\)表示我想计算区间\([l,r]\)的答案,然后转移过来的区间在\([ql,qr]\) 暴力计算出\(f[mid]\)的值,找到最优转移点是\(k\),然后分成\(Solve(l,m…
F. Yet Another Minimization Problem http://codeforces.com/contest/868/problem/F 题意: 给定一个长度为n的序列.你需要将它分为m段,每一段的代价为这一段内相同的数的对数,最小化代价总和. n<=100000,m<=20. 分析: f[k][j]=min{f[k-1][j]+cost(k,j,i)}; cost发现不能快速的算出.于是不能用类似单调队列+二分的方法来做了. 考虑分治,solve(Head,Tail,L…
目录 题目链接 题解 代码 题目链接 CF868F. Yet Another Minimization Problem 题解 \(f_{i,j}=\min\limits_{k=1}^{i}\{f_{k,j-1}+w_{k,i}\}\) \(w_{l,r}\)为区间\([l,r]\)的花费,1D1D的经典形式 发现这个这是个具有决策单调性的转移 单无法快速转移,我们考虑分治 对于当前分治区间\([l,r]\) ,它的最优决策区间在\([L,R]\)之间. 对于\([l,r]\)的中点\(mid\)…
Yet Another Minimization Problem 一个很显然的决策单调性. 方程是很显然的 $ f_i = \min{f_{j-1} + w(j,i)} $ . 它具有决策单调性,可以参考钟神的 Blog 我们考虑怎么实现这个东西,按照上次 DLS 讲的,考虑 solve(l,r,L,R) 表示 我们当前在处理 $ l,r $ 的 $ dp $ 值,我们知道当前决策点在 $ L,R $ 内. 然后考虑怎么求,先对 $ mid $ 暴力跑出决策位置,然后分治 solve(l,mid…
http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的概率最大. Solution 很显然的概率dp,过了样例即可AC..话说我为什么要刷B题→_→ 代码 // codeforces442B #include<algorithm> #include<iostream> #include<cstdlib> #include<…
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description Sonny uses a very peculiar pattern when it comes to playing rock-paper-scissors. He likes to vary his moves so that his opponent can't beat him with hi…
当在Codeforces上做题的时,有时会无意撇到右侧的Problem tags边栏,但是原本并不希望能够看到它. 能否把它屏蔽了呢?答案是显然的,我们只需要加一段很短的CSS即可. span.tag-box{ display: none; } 这样,当这段CSS生效时,标签将会变成如下所示的样子. 这样目的就达到了. 那么,如何将CSS应用到浏览器中使其生效呢?对于不同的浏览器有不同的方法.下面以主流浏览器为例. 对于Safari,将上述代码另存为.css文件,然后在偏好设置->高级->样式…
这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. 于是想是不是有什么规律,于是推导了一下,推了一个出来,写成代码提交之后发现是错的. 最后就没办法了,剩下的时间不够写dfs,于是就放弃了. 今天看thnkndblv的代码,代码非常短,于是就想肯定是有什么数学规律,于是看了一下, 果然如此. 是这种,还是枚举,当然是有技巧的,看我娓娓道来. 枚举的话…
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1005 using namespace std; char a[maxn][maxn]; int ans; void solve…
题目链接:http://codeforces.com/problemset/problem/803/G 大致就是线段树动态开节点. 然后考虑到如果一个点还没有出现过,那么这个点显然未被修改,就将这个点所代表的区间定位到原序列中,利用ST表查一下区间最小值就可以了. 定位: llg minn(llg l,llg r) { >=n) return mt; l%=n;if(!l) l=n; r%=n;if(!r) r=n; ,r)); else return gw(l,r); } 其中${gw(l,r…
题目传送门 传送门I 传送门II 传送门III 题目大意 给定一个网络.网络分为$A$,$B$两个部分,每边各有$n$个点.对于$A_{i} \ (1\leqslant i < n)$会向$A_{i + 1}$连一条容量为$x_{i}$的有向边,对于$B_{i} \ (1\leqslant i < n)$会向$B_{i + 1}$连一条容量为$y_{i}$的有向边.$A$和$B$之间有$m$条边,起点为$A_{u_{i}}$,终点为$B_{v_{i}}$,容量为$w_{i}$的有向边.要求支持…
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence. The space is represented by a rectangular grid of n × m cells, arranged into n…
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii-chan! With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewher…
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lif…
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer n is decided first. Both Koyomi a…
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes. A string is 1-palindrome if and only if it reads the same backward as f…
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c). Over time the stars twinkle. At moment 0 the i-th…
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The secon…
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to h…
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n…
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consis…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…
C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful…
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1,可以执行一次操作使ai,ai+1变为ai - ai + 1, ai + ai + 1.求出使得gcd(a1,a2,....an)>1所需要的最小操作数. 解题思路:首先,要知道如果能够实现gcd(a1,a2,....an)>1,那么a1~an肯定都是偶数(0也是偶数),所以我们的目的就是用最少的操…
[题目链接]:http://codeforces.com/contest/776/problem/D [题意] 每个门严格由两个开关控制; 按一下开关,这个开关所控制的门都会改变状态; 问你能不能使所有的门都打开(同时); [题解] /* 对于每个门, 有两个开关连接着它; 用一条边连接这两个开关 则如果这个门的状态是关的, 则这条边的边权为1 表示它们俩的颜色不能一样; (也即这两个开关只能改变一个) 也即要1开1关; 如果这个门的状态是开的 则这条边的边权为0: 表示它们俩的颜色相同; 即同…