CodeForces 834D The Bakery】的更多相关文章

Codeforces 834D The Bakery LINK 题目大意是给你一个长度为n的序列分成k段,每一段的贡献是这一段中不同的数的个数,求最大贡献 是第一次做线段树维护DP值的题 感觉还可以,虽然看了一下这题是用线段树维护DP值 然后说思路 有一个很显然的思路是这样的: dpi,j表示前i个数分成j段的最大贡献 dpi,j=max(dpk,j−1+calc(k+1,i)) 然后我们就可以对于每一层j用线段树维护起来 然后就非常愉快地发现dp[i][p]只会从dp[i−1][p−1]之前的…
834D - The Bakery 思路:dp[i][j]表示到第j个数为止分成i段的最大总和值. dp[i][j]=max{dp[i-1][x]+c(x+1,j)(i-1≤x≤j-1)},c(x+1,j)表示x+1到j的不同的值. 用线段树维护一下最大值. 上图最后一个点取不到,不解释,不明白请评论. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define ls rt<<1,l,m…
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decid…
D. The Bakery time limit per test:2.5 seconds memory limit per test:256 megabytes input:standard input output:standard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven whic…
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decid…
The Bakery 题意:将N个数分成K块, 每块的价值为不同数字的个数, 现在求总价值最大. 题解:dp[i][j] 表示 长度为j 且分成 i 块的价值总和. 那么 dp[i][j] = max(dp[i-1][x]+右边的数的贡献) ( 1<=x < j ). 如果每次都从左到右for过去一定会TLE, 所以我们用线段树来优化这个查询的过程, 并且用滚动数组消去第二维空间. 每次新扫到一个数T, 他就会在上一个T的位置+1 --- 现在这个T的位置产生数目加一的贡献. 然后每次扫完一次…
D - The Bakery CodeForces - 834D 这个题目好难啊,我理解了好久,都没有怎么理解好, 这种线段树优化dp,感觉还是很难的. 直接说思路吧,说不清楚就看代码吧. 这个题目转移方程还是很好写的, dp[i][j]表示前面 i 个蛋糕 分成了 j 个数字的最大价值. dp[i][j]=max(dp[k][j-1]+val[k+1~i]) 显而易见的是,这个肯定不可以直接暴力求,所以就要用到线段树优化. 线段树怎么优化呢, 先看这个问题,给你一个点 x ,问你以这个点为右端…
E. Ever-Hungry Krakozyabra time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Recently, a wild Krakozyabra appeared at Jelly Castle. It is, truth to be said, always eager to have something for…
B. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven whic…
题目链接: B. Bakery 题意: 是否存在一条连接特殊和不特殊的边,存在最小值是多少; 思路: 扫一遍所有边: AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> #include &l…