CF833B The Bakery (线段树+DP)】的更多相关文章

题目大意:给你一个序列(n<=35000),最多分不大于m块(m<=50),求每个块内不同元素的数量之和的最大值 考试的时候第一眼建图,没建出来,第二眼贪心 ,被自己hack掉了,又随手写了个dp方程,感觉可以用splay维护,发现有区间操作并可取,又发现这个方程只能用线段树维护,然后只剩40min了我没调完,而且线段树打错了...... 定义f[i][j]表示以第i个数为这个块的结尾,已经分了j块的答案的最大值 很明显,sum表示不同元素数量 对于每个元素,记录一个表示数 i 上一次出现的位…
CF833B The Bakery LG传送门 线段树优化DP. 其实这是很久以前就应该做了的一道题,由于颓废一直咕在那里,其实还是挺不错的一道题. 先考虑\(O(n^2k)\)做法:设\(f[i][j]\)表示\(1\)到\(i\)之间分割\(j\)次得到的最大值,\(g[i][j]\)表示\(i\)到\(j\)之间不同的颜色个数. 转移就是: \[f[i][j]=max \{f[t][j-1]+g[t+1][i] \} \qquad t \in [1,i)\] 但是时空都无法承受,考虑优化.…
B. The Bakery   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…
题目链接 \(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://www.tsinsen.com/A1219 [题意] 给定一棵树,a[u][i]代表u结点分配i人的收益,可以随时改变a[u],查询(u,v)代表在u子树的所有节点,在u->v(不含u)路径上的节点分配人数的最优收益. [思路] 树链剖分:构造重链时先访问重儿子,因此一个重链的区间连续,同时一个子树的区间连续. 查询分为两部分:构造在u子树内分配人数i的最大收益ans1[i],以及构造在u->v路径上一个结点分配人数i的最大收益ans2[i].则ans=max{ a…
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1391    Accepted Submission(s): 483 Problem Description The Game “Man Down 100 floors” is an famous and interesting ga…
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…
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 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 which…
D. The Bakery   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…