[CF484D] Kindergarten - 贪心】的更多相关文章

有一组数,你要把他分成若干连续段.每一段的值,定义为这一段 数中最大值与最小值的差. 求一种分法,使得这若干段的值的和最大. N < 1e6, a[i] < 1e9. 朴素的\(O(n^2)\) dp 设\(f[i]\)表示分前\(i\)个数可以得到的最大和,则 \[f_i = Max_{0 \leq j < i}(f[j]+Query(j+1,i))\] 其中\(Query(l,r)\)表示的是\([l,r]\)段的值域大小,可以通过\(O(n^2)\)预处理得到,然后\(O(n^2)…
D. Kindergarten     In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should b…
题目大意: n 个人 在选取班长 1号十分想当班长,他已经知道其他人选择了谁,但他可以贿赂其他人改选他,问贿赂的最小值 ps.他自己也要投一个人 要处理一个问题是,他自己投谁 其实这个问题在这种局面下在不同算法有不同处理方法,先不要考虑 一开始我想的是纯贪心: 选2个最小的比较票数最多中最小的  谁小选哪个 直到1号票数最多(但不是唯一) 这个时候再考虑 他投给谁 1.如果有一个人票数跟他一样多x ,这个时候1号还要拿一票,谁给他一票他就投给谁,不影响结果(给他同样票数的人,那个人票数不变,1号…
题意:给n个数,分成若干个连续组,每组获益为max-min,输出最大获益. 参考:http://blog.csdn.net/keshuai19940722/article/details/40873581 参考的链接里说得很明白了,我的dp[i][0]是升序,dp[i][1]是降序,习惯而已. 这题关键点就是,如果a[i-1]<a[i]>a[i+1],显然3个分开(a[i]归左或右)不比在一起差. #include <cstdio> #include <cstring>…
大意: 给定序列, 求划分为若干段, 使得总贡献最大, 每段的贡献为max-min 可以发现最优解一定是连续一段递增或递减, 然后dp即可. #include <iostream> #include <cstdio> #define REP(i,a,n) for(int i=a;i<=n;++i) using namespace std; typedef long long ll; const int N = 1e6+10; int n, a[N]; ll dp[2][N];…
HackerRank - candies [贪心] Description Alice is a kindergarten teacher. She wants to give some candies to the children in her class. All the children sit in a line (their positions are fixed), and each of them has a rating score according to his or he…
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][Status][Discuss] Description FJ打算带他的N(1 <= N <= 30,000)头奶牛去参加一年一度的“全美农场主大奖赛”.在这场比赛中,每个参赛者都必须让他的奶牛排成一列,然后领她们从裁判席前依次走过. 今年,竞赛委员会在接受队伍报名时,采用了一种新的登记规则:他们把所…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15564    Accepted Submission(s): 6405 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g…
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][Status][Discuss] Description 与很多奶牛一样,Farmer John那群养尊处优的奶牛们对食物越来越挑剔,随便拿堆草就能打发她们午饭的日子自然是一去不返了.现在,Farmer John不得不去牧草专供商那里购买大量美味多汁的牧草,来满足他那N(1 <= N <= 100,…