HDOJ 3507 Print Article
Print Article
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 3827 Accepted Submission(s): 1195
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.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; typedef long long int LL; LL dp[],sum[],deq[];
int n,m,s,t,e; double slope(int i,int j)
{
return (double)(dp[i]+sum[i]*sum[i]-dp[j]-sum[j]*sum[j])/(sum[i]-sum[j]);
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
sum[]=;
for(int i=;i<=n;i++)
{
scanf("%d",sum+i);
sum[i]+=sum[i-];
}
s=;
for(int i=;i<=n;i++)
{
if(sum[i]!=sum[s])
{
s++;
sum[s]=sum[i];
}
}
n=s;
s=,e=,dp[]=,deq[]=;
for(int i=;i<=n;i++)
{
while(s<e&&slope(deq[s],deq[s+])<=*sum[i]) s++;
int j=deq[s];
dp[i]=dp[j]+(sum[i]-sum[j])*(sum[i]-sum[j])+m;
while(s<e&&slope(deq[e-],deq[e])>=slope(i,deq[e])) e--; e++;
deq[e]=i;
}
printf("%d\n",dp[n]);
}
return ;
}
HDOJ 3507 Print Article的更多相关文章
- hdu 3507 Print Article(斜率优化DP)
题目链接:hdu 3507 Print Article 题意: 每个字有一个值,现在让你分成k段打印,每段打印需要消耗的值用那个公式计算,现在让你求最小值 题解: 设dp[i]表示前i个字符需要消耗的 ...
- HDU 3507 Print Article 斜率优化
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- HDU 3507 Print Article(DP+斜率优化)
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- DP(斜率优化):HDU 3507 Print Article
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- HDU 3507 - Print Article - [斜率DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3507 Zero has an old printer that doesn't work well s ...
- [HDU 3507]Print Article
Description Zero has an old printer that doesn't work well sometimes. As it is antique, he still lik ...
- HDU 3507 Print Article(CDQ分治+分治DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3507 [题目大意] 将长度为n的数列分段,最小化每段和的平方和. [题解] 根据题目很容易得到dp ...
- ●HDU 3507 Print Article
题链: http://acm.hdu.edu.cn/showproblem.php?pid=3507 题解: 斜率优化DP 一个入门题,就不给题解了,网上的好讲解很多的. 这里就只提一个小问题吧( ...
- hdu 3507 Print Article —— 斜率优化DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3507 设 f[i],则 f[i] = f[j] + (s[i]-s[j])*(s[i]-s[j]) + m ...
随机推荐
- CentOS设置防火墙开放端口
1. iptables是linux下的防火墙,同时也是服务的名称. service iptables status service iptables start service iptables st ...
- HDU #2966 In case of failure
Overview 给出平面上两两不重合的\(n\)个整点, 求每个点到它在其他\(n-1\)个点的最近临点的欧几里得距离的平方. Solution k-d tree 模板题. 关于k-d tree, ...
- 更改primefaces theme
PrimeFaces is using jQuery ThemeRoller CSS theme framework, and come with 30+ pre-designed themes th ...
- iOS - 沙盒中,如何判断存在文件、目录
在iOS开发中,在沙盒中创建沙盒一些存储各个功能的文件目录或者文件. 使用: [NSFileManager defaultManager] 1.判断目录,用她可以. 2.判断文件,用她可以. 3.创建 ...
- Altium Designer 15 --- Nets Update
Now I want to introduce the use of 'Configure Physical Nets', as follows: If you has finished the PC ...
- B450黑苹果之路(1)
安装黑苹果,采取的是懒人版写入磁盘分区中,然后再安装1)从硬盘中分两个区,一个是未来使用的目标分区,一个是磁盘镜像区2)由于HFS+支持逻辑分区,所以两个分区都放逻辑分区上,分区不格式化3)使用硬盘助 ...
- 自然语言12_Tokenizing Words and Sentences with NLTK
https://www.pythonprogramming.net/tokenizing-words-sentences-nltk-tutorial/ # -*- coding: utf-8 -*- ...
- JavaScript学习笔记——事件
javascript事件基础和事件绑定 一.事件驱动 1.事件 javascript侦测到的用户的操作或是页面的一些行为(怎么发生的) 2.事件源 引发事件的元素.(发生在谁的身上)3.事件处理程序 ...
- docker管理shipyard中文版v3.0.2更新
shipyard中文版v3.0.2更新 https://console.dockerclub.net/ https://dockerclub.net/docs/intro/getting_start ...
- idea配置2个tomcat
复制tomcat 分别放在不同地方