hdu3507Print Article

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

Total Submission(s): 6455    Accepted Submission(s): 1990

Problem Description

Zero has an old printer that doesn‘t work well sometimes. As it is antique, he still like to use it to print articles. But it is too old to work for a long time and it will certainly wear and tear, so Zero use a cost to evaluate this
degree.

One day Zero want to print an article which has N words, and each word i has a cost Ci to be printed. Also, Zero know that print k words in one line will cost

M is a const number.

Now Zero want to know the minimum cost in order to arrange the article perfectly.

Input

There are many test cases. For each test case, There are two numbers N and M in the first line (0 ≤ n ≤
500000, 0 ≤ M ≤ 1000). Then, there are N numbers in the next 2 to N + 1 lines. Input are terminated by EOF.

Output

A single number, meaning the mininum cost to print the article.

Sample Input

5 5
5
9
5
7
5

Sample Output

230

Author

Xnozero

Source

2010 ACM-ICPC Multi-University Training Contest(7)——Host
by HIT

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
int sum[500010],dp[500010],q[500010];
int gety(int i,int j)
{
	return dp[i]-dp[j]+(sum[i]+sum[j])*(sum[i]-sum[j]);
}
int getx(int i,int j)
{
	return 2*(sum[i]-sum[j]);
}
int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++)
		{
			cin>>sum[i];
			sum[i]+=sum[i-1];
		}
		int head(0),tail(1);
		for(int i=1;i<=n;i++)
		{
			while(head+1<tail&&gety(q[head+1],q[head])<=sum[i]*getx(q[head+1],q[head]))
				head++;
			dp[i]=dp[q[head]]+(sum[i]-sum[q[head]])*(sum[i]-sum[q[head]])+m;
			while(head+1<tail&&gety(i,q[tail-1])*getx(q[tail-1],q[tail-2])<=getx(i,q[tail-1])*gety(q[tail-1],q[tail-2]))
				tail--;
			q[tail++]=i;
		}
		cout<<dp[n]<<endl;
	}
}
时间: 2024-10-13 12:34:24

hdu3507Print Article的相关文章

hdu3507Print Article(斜率优化dp)

Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 12824    Accepted Submission(s): 3967 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antiqu

latex三种标准文类book, report, article的章节命令与层次深度

Latex有三种标准文类:book, report, article. 每种文类的章节命令和层次深度如下: 三种标准文类的章节命令与层次深度 层次深度 层次名 book report article -1 part \part \part   0 chapter \chapter \chapter \part 1 section \section \section \section 2 subsection \subsection \subsection \subsection 3 subsub

hdu 4416 Good Article Good sentence(后缀数组&amp;思维)

Good Article Good sentence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2308    Accepted Submission(s): 649 Problem Description In middle school, teachers used to encourage us to pick up pre

The first article

终于,下决心要留下点痕迹了..... 今天的学习心得就记录一下罗... 首先.redis 是个什么东东? 内存高速缓存数据库,key-value存储系统,支持丰富的数据类型:string.list.set.zset.hash; 特点:数据持久化,断电或重启数据也不会丢失,存储分为内存存储.磁盘存储和log文件,支持主从模式,读写速度高: 单进程单线程模式 应用场景:redis分布式锁实现多台tomcat服务器+redis[多台tomcat服务器访问一台redis]+mysql[多台tomcat服

hdu3507 Print Article[斜率优化dp入门题]

Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 11761    Accepted Submission(s): 3586 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antiqu

HTML5的article和section的区别

内容区块是指将HTML页面按逻辑分割后的单位.对于页面网站来说,导航菜单.文章正文.文章的评论等每一个部分都可称为内容区块.      article元素      article元素代表文档.页面或应用程序中独立的.完整的.可以独自被外部引用的内容.它可以是一篇博客或报刊中的文章.一篇论坛帖子.一段用户评论或独立的插件,或其他任何独立的内容.除了内容部分,一个article元素通常有它自己的标题(一般放在一个header元素里面),有时还有自己的脚注.<article>      <h

[UI] Article intro effects

Article intro effects http://freebiesbug.com/code-stuff/article-intro-effects/

hdu 4416 Good Article Good sentence (后缀数组)

题目大意: 给出一个A串和很多个B串,求出A中有多少个子串,是所有的B中没有出现的. 思路分析: 后缀数组的作用很容易的求出来整个串中不同的子串个数. 现在要求的是A中不同的,且在B中没有出现过的. 先把AB 串全部连接,跑一遍suffix array.然后求出有多少个不同的子串. 然后再单独用B 串跑 suffix array.再求出单独在B 中有多少个不同的 子串. 然后结果就是 ans1 - ans2 ... 需要注意的问题就是,连接的时候需要把每一个串后面加一个特殊符.但是求不同串的时候

中文录入问题 转载自:http://blog.csdn.net/ichsonx/article/details/8625925

2.1中文录入问题 默认安装的msysgit的shell环境中无法输入中文,为了能在shell界面输入中文,需要修改配置文件/etc/inputrc,增加或修改相关配置如下: #disable/enable 8bit input set meta-flag on set input-meta on set output-meta on set convert-meta off 关闭bash再重启就可以输入中文了. 2.2分页器中文输出问题 对于/etc/inputrc正确配置之后能正确输入中文了