3675: [Apio2014]序列分割
来源:互联网 发布:倍投软件下载 编辑:程序博客网 时间:2024/05/17 09:12
3675: [Apio2014]序列分割
Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 1891 Solved: 776
[Submit][Status][Discuss]
Description
小H最近迷上了一个分隔序列的游戏。在这个游戏里,小H需要将一个长度为n的非负整数序列分割成k+1个非空的子序列。为了得到k+1个子序列,小H需要重复k次以下的步骤:
1.小H首先选择一个长度超过1的序列(一开始小H只有一个长度为n的序列——也就是一开始得到的整个序列);
2.选择一个位置,并通过这个位置将这个序列分割成连续的两个非空的新序列。
每次进行上述步骤之后,小H将会得到一定的分数。这个分数为两个新序列中元素和的乘积。小H希望选择一种最佳的分割方式,使得k轮之后,小H的总得分最大。
Input
输入第一行包含两个整数n,k(k+1≤n)。
第二行包含n个非负整数a1,a2,...,an(0≤ai≤10^4),表示一开始小H得到的序列。
Output
输出第一行包含一个整数,为小H可以得到的最大分数。
Sample Input
7 3
4 1 3 4 0 2 3
4 1 3 4 0 2 3
Sample Output
108
HINT
【样例说明】
在样例中,小H可以通过如下3轮操作得到108分:
1.-开始小H有一个序列(4,1,3,4,0,2,3)。小H选择在第1个数之后的位置
将序列分成两部分,并得到4×(1+3+4+0+2+3)=52分。
2.这一轮开始时小H有两个序列:(4),(1,3,4,0,2,3)。小H选择在第3个数
字之后的位置将第二个序列分成两部分,并得到(1+3)×(4+0+2+
3)=36分。
3.这一轮开始时小H有三个序列:(4),(1,3),(4,0,2,3)。小H选择在第5个
数字之后的位置将第三个序列分成两部分,并得到(4+0)×(2+3)=
20分。
经过上述三轮操作,小H将会得到四个子序列:(4),(1,3),(4,0),(2,3)并总共得到52+36+20=108分。
【数据规模与评分】
:数据满足2≤n≤100000,1≤k≤min(n -1,200)。
Source
#include<iostream>#include<cstdio>#include<queue>#include<vector>#include<bitset>#include<algorithm>#include<cstring>#include<map>#include<stack>#include<set>#include<cmath>#include<ext/pb_ds/priority_queue.hpp>using namespace std;const int maxn = 1E5 + 10;typedef long long LL;struct Point{LL x,y;Point(){}Point(LL x,LL y): x(x),y(y){}Point operator - (const Point b) {return Point(x - b.x,y - b.y);}}p[2][maxn];typedef Point Vector;int n,k,head,tail,cur,Q[maxn];LL Ans,sum[maxn],f[2][maxn];LL Cross(Vector v1,Vector v2) {return v1.x*v2.y - v2.x*v1.y;}LL Work(int j,int i) {return f[cur^1][j] + sum[j]*(sum[i] - sum[j]);}bool Judge(int j,int t,int i){Point poi = p[cur^1][t] - p[cur^1][j];if (poi.x < 0)poi.x *= -1,poi.y *= -1;return poi.y >= -poi.x*sum[i];}bool judge(int j,int t,int i){Vector A = p[cur^1][t] - p[cur^1][j];Vector B = p[cur^1][i] - p[cur^1][t];return Cross(A,B) >= 0;}int getint(){char ch = getchar();int ret = 0;while (ch < '0' || '9' < ch) ch = getchar();while ('0' <= ch && ch <= '9')ret = ret*10 + ch - '0',ch = getchar();return ret;}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifn = getint(); k = getint();for (int i = 1; i <= n; i++)sum[i] = getint(),sum[i] += sum[i-1];for (int i = 1; i <= n; i++)p[cur][i] = Point(sum[i],f[cur][i] - sum[i]*sum[i]);for (int t = 2; t <= k + 1; t++) {Q[head = tail = 1] = t - 1;cur ^= 1;for (int i = t; i <= n; i++) {while (head < tail && Judge(Q[head],Q[head+1],i))++head;LL now = Work(Q[head],i);while (head < tail && judge(Q[tail-1],Q[tail],i))--tail;Q[++tail] = i;f[cur][i] = now;p[cur][i] = Point(sum[i],f[cur][i] - sum[i]*sum[i]);}}cout << f[cur][n];return 0;}
0 0
- 3675: [Apio2014]序列分割
- 3675: [Apio2014]序列分割
- bzoj 3675: [Apio2014]序列分割
- BZOJ 3675: [Apio2014]序列分割
- [BZOJ 3675][Apio2014]序列分割
- BZOJ 3675: [Apio2014]序列分割
- BZOJ 3675: [Apio2014]序列分割
- BZOJ 3675 APIO2014 序列分割 斜率优化
- bzoj 3675 [Apio2014]序列分割 斜率优化
- 【DP】 BZOJ 3675: [Apio2014]序列分割
- 【斜率DP】BZOJ 3675:[Apio2014]序列分割
- 3675: [Apio2014]序列分割 斜率优化DP
- BZOJ 3675 [Apio2014] 序列分割 斜率优化
- APIO2014序列分割bzoj3675
- bzoj3675: [Apio2014]序列分割
- [BZOJ3675][Apio2014]序列分割
- [BZOJ3675] [Apio2014]序列分割
- bzoj3675【APIO2014】序列分割
- window磁盘管理下面的“未分配”与“可用空间”
- 查找php extension目录
- js中对象与继承
- 第五周项目1-三角形类雏形(1)
- APIClound android和ios的控制台调试
- 3675: [Apio2014]序列分割
- 文章标题
- Spring整合Hibernate,Druid(Maven)
- 第五周项目1-三角形类雏形(2)
- 40. Combination Sum II
- 构造函数可以调用虚函数吗?语法上通过吗?语义上可以通过吗?
- 第四章 μCOS-Ⅱ的中断和时钟
- linux下打开、关闭tomcat,实时查看tomcat运行日志
- mangos源码分析