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

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)\) 然后用线段树优化一下, 一个数的贡献是上一个相同数字…
题 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…
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…
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…
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…
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…
B. Bakery 题目连接: http://www.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.…
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]之前的…
D - The Bakery CodeForces - 834D 这个题目好难啊,我理解了好久,都没有怎么理解好, 这种线段树优化dp,感觉还是很难的. 直接说思路吧,说不清楚就看代码吧. 这个题目转移方程还是很好写的, dp[i][j]表示前面 i 个蛋糕 分成了 j 个数字的最大价值. dp[i][j]=max(dp[k][j-1]+val[k+1~i]) 显而易见的是,这个肯定不可以直接暴力求,所以就要用到线段树优化. 线段树怎么优化呢, 先看这个问题,给你一个点 x ,问你以这个点为右端…
题目链接: http://codeforces.com/problemset/problem/707/B 题目大意: 给你N个点M条无向边,其中有K个面粉站,现在一个人要在不是面粉站的点上开店,问到面粉站的最短距离是多少.无法开店输出-1. 题目思路: [最小生成树] 把边长按距离从小到大排序,出现的第一个只含一个面粉店的边为所求. // //by coolxxx //#include<bits/stdc++.h> #include<iostream> #include<al…