Codeforces 833B / B34D The Bakery】的更多相关文章

题 OwO http://codeforces.com/contest/833/problem/B 解 首先读入的时候把数据读入到2 ~ n+1的位置(因为线段树处理不到0,所以后移了一格) dp[i][j]代表处理到第i个位置为止,分j段能得到的最大值 lst[i]记录第与第i个蛋糕一样的蛋糕出现的上一个位置 则,显然dp[i][j]=min(dp[i-t][j-1]+(从i-t+1到i位置的不同种类的蛋糕个数)) 记对每一段的值有贡献的点为同一段每种类型蛋糕最左边的点(比如其中一段AAFBC…
codeforces 834 D. The Bakery(dp + 线段树优化) 题意: 给一个长度为n的序列分成k段,每段的值为这一段不同数字的个数,最大化划分k端的值 $n <= 35000 $ \(k <= min(n,50)\) 思路: 由于k比较小,直接dp就好了 \(dp[i][j]\)选了k段到j的最大值 \(dp[i][j] = max(dp[i-1][k]+diff(k+1,j)) (0 <= k < j)\) 然后用线段树优化一下, 一个数的贡献是上一个相同数字…
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…
题目链接 The Bakery 题目大意:目标是把$n$个数分成$k$组,每个组的值为这个组内不同的数的个数,求$k$个组的值的和的最大值. 题目分析: 这道题我的解法可能和大众解法不太一样……我用主席树求$ask(l, r)$——$l$到$r$之间有多少个不同的数. 然后就是$DP$了. 这道题的数据规模是 $n <= 35000$, $k <= 50$ 首先直接$DP$的做法还是比较简单的.代码如下. 其中$f[i][j]$为前$i$个数分成$j$组可以得到的最大的和 rep(i, 1,…
题解: 线段树经典应用 首先暴力$f[i][j]$表示考虑前i位分成j段的最大值 转移$f[k][j-1]+cost(k+1,i)$枚举k转移 不同数的经典套路就是从它到它前驱这一段 于是维护每个数前驱然后线段树区间+1区间查询最大值就可以了…
题目链接 \(Description\) 有n个数,将其分为k段,每段的值为这一段的总共数字种类,问最大总值是多少 \(Solution\) DP,用\(f[i][j]\)表示当前在i 分成了j份(第j份包括i) 那枚举前边的断点k,即 \(f[i][j]=max{f[k][j-1]+val(k+1,1)}\) \(val(a,b)\)表示\([a,b]\)这段区间的价值(数字种数) \(O(n^2*k)\) 第二维可以滚动数组优化掉,只在最外层枚举即可 优化求\(val()\)的过程 val是…
题面 传送门:http://codeforces.com/problemset/problem/833/B B. The Bakery time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She…
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake…
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…