Print Article

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4990    Accepted Submission(s): 1509

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
 
 
 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std;
int a[],sum[],h[],dp[],m;
int getup(int j,int k)
{
return dp[j]+sum[j]*sum[j]-dp[k]-sum[k]*sum[k];
}
int getdown(int j,int k)
{
return ((sum[j]-sum[k])<<);
}
int getdp(int i,int j)
{
return dp[j]+m+(sum[i]-sum[j])*(sum[i]-sum[j]);
}
int main()
{
int n,i,head,tail;
while(~scanf("%d%d",&n,&m))
{
memset(h,,sizeof(h));
sum[]=a[]=;
for(i=; i<=n; i++)
scanf("%d",&a[i]),sum[i]=sum[i-]+a[i];
head=tail=;
h[tail++]=;
for(i=;i<=n;i++)
{
while(head+<tail&&getup(h[head+],h[head])<=sum[i]*getdown(h[head+],h[head]))
head++;
dp[i]=getdp(i,h[head]);
while(head+<tail&&getup(h[tail-],h[tail-])*getdown(i,h[tail-])>=getup(i,h[tail-])*getdown(h[tail-],h[tail-]))
tail--;
h[tail++]=i;
}
cout<<dp[i-]<<endl;
}
}

Print Article hdu 3507 一道斜率优化DP 表示是基础题,但对我来说很难的更多相关文章

  1. 斜率dp A - Print Article HDU - 3507

    A - Print Article HDU - 3507 今天刚刚学习了一下斜率dp,感觉还ok,主要就是要推这个斜率,然后利用数据结构来优化. 推荐两篇写的比较好的博客,https://www.cn ...

  2. hdu 2829 Lawrence(斜率优化DP)

    题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...

  3. HDU 2829 Lawrence (斜率优化DP或四边形不等式优化DP)

    题意:给定 n 个数,要你将其分成m + 1组,要求每组数必须是连续的而且要求得到的价值最小.一组数的价值定义为该组内任意两个数乘积之和,如果某组中仅有一个数,那么该组数的价值为0. 析:DP状态方程 ...

  4. hdu 3480 Division(斜率优化DP)

    题目链接:hdu 3480 Division 题意: 给你一个有n个数的集合S,现在让你选出m个子集合,使这m个子集合并起来为S,并且每个集合的(max-min)2 之和要最小. 题解: 运用贪心的思 ...

  5. Print Article HDU - 3507 -斜率优化DP

    思路 : 1,用一个单调队列来维护解集. 2,假设队列中从头到尾已经有元素a b c.那么当d要入队的时候,我们维护队列的下凸性质, 即如果g[d,c]<g[c,b],那么就将c点删除.直到找到 ...

  6. HDU 6619 Horse 斜率优化dp

    http://acm.hdu.edu.cn/showproblem.php?pid=6619 #include<bits/stdc++.h> #define fi first #defin ...

  7. 2018.08.28 洛谷P4360 [CEOI2004]锯木厂选址(斜率优化dp)

    传送门 一道斜率优化dp入门题. 是这样的没错... 我们用dis[i]表示i到第三个锯木厂的距离,sum[i]表示前i棵树的总重量,w[i]为第i棵树的重量,于是发现如果令第一个锯木厂地址为i,第二 ...

  8. bzoj 1597 [Usaco2008 Mar]土地购买——斜率优化dp

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1597 又一道斜率优化dp.负数让我混乱.不过仔细想想还是好的. 还可以方便地把那个负号放到x ...

  9. 【洛谷3648】[APIO2014] 序列分割(斜率优化DP)

    点此看题面 大致题意: 你可以对一个序列进行\(k\)次分割,每次得分为两个块元素和的乘积,求总得分的最大值. 区间\(DPor\)斜率优化\(DP\) 这题目第一眼看上去感觉很明显是区间\(DP\) ...

随机推荐

  1. 读取xml文件中节点

    /// <summary> /// /// </summary> /// <param name="xmlpath">节点路径</para ...

  2. html:table属性cellpadding

    cellpadding:单元格边距(空白区域) colspan:可以横跨的列数(td/th都算一列) 详细:http://www.dreamdu.com/xhtml/attribute_cellpad ...

  3. HK2框架的简单自实现kunJ

    kunJ kunJ框架,是基于HK2框架的一个自实现注入框架,功能比较简单,重在探索依赖注入的实现原理. 实现细节 自定义3个注解,Access,Inject,Service 在Service中实现对 ...

  4. mysql 数据库安装步骤个人总结

    1.mysql-5.7.19-winx64.zip(此为免安装版,318兆左右,还有一种是安装版,380兆左右mysql-installer-community-5.7.19.0.msi)将此安装包解 ...

  5. 安装mariadb二进制程序

    author:JevonWei 版权声明:原创作品 下载mariadb软件包 https://downloads.mariadb.org/mariadb/5.5.57/ 一.创建用户和准备数据目录 1 ...

  6. Myeclipse 自定义java代码快捷键

    1.首先在MyEclipse菜单栏找到"windows"下拉菜单中找到首选项(英文Prefenerces),弹出首选项界面.   2.打开java -->editor---& ...

  7. Java中 Comparator接口 与Comparable 的区别

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt159 comparator接口与Comparable接口的区别 1. Com ...

  8. mpls vpn剩余笔记

    将IP地址映射为简单的具有固定长度的标签 用于快速数据包交换 20 3 1 8 在整个转发过程中,交换节点仅根据标记进行转发 标签交换路径(LSP) 多协议标签交换MPLS最初是为了提高转发速度而提出 ...

  9. 201521123108《Java程序设计》第1周学习总结

    本周学习总结 刚加入java的学习,我感觉很困难.但我觉得学习并不是一蹴而就.只要我多读,多看,多练,一定会取得进步.有空的时候把书本上的代码敲一敲.相信会有回报. 2.书面作业 1.为什么java程 ...

  10. ubuntu下php不能显示中文的问题的解决过程。

    在阿里的ECS上的ubuntu平台上成功的安装了apache2和php5与mysql,并进行了测试. 如图所示: