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 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
 
Recommend
zhengfeng   |   We have carefully selected several
similar problems for you:  3506 3501 3504 3505 3498 
 
斜率优化dp学习:http://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html
 
#include<iostream>
#include<cstdio>
#include<cstring> #define N 500005 using namespace std;
int dp[N],q[N],sum[N];
int head,tail,n,m; int get_dp(int i,int j)
{
return dp[j]+m+(sum[i]-sum[j])*(sum[i]-sum[j]);
} int get_up(int j,int k)
{
return dp[j]+sum[j]*sum[j]-(dp[k]+sum[k]*sum[k]);
} int get_down(int j,int k)
{
return *(sum[j]-sum[k]);
} int main()
{
while(scanf("%d%d",&n,&m)==)
{
for(int i=;i<=n;i++) scanf("%d",&sum[i]);
sum[]=dp[]=;head=tail=;
for(int i=;i<=n;i++) sum[i]+=sum[i-];
q[tail++]=;
for(int i=;i<=n;i++)
{
while(head+<tail && get_up(q[head+],q[head])<=sum[i]*get_down(q[head+],q[head]))
head++;
dp[i]=get_dp(i,q[head]);
while(head+<tail && get_up(i,q[tail-])*get_down(q[tail-],q[tail-])<=get_up(q[tail-],q[tail-])*get_down(i,q[tail-]))
tail--;
q[tail++]=i;
}
printf("%d\n",dp[n]);
}
return ;
}

hdu3507Print Article(斜率优化dp)的更多相关文章

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

    学习:https://blog.csdn.net/bill_yang_2016/article/details/54667902 HDU-3507 题意:有若干个单词,每个单词有一个费用,连续的单词组 ...

  2. HDU3507 Print Article(斜率优化dp)

    前几天做多校,知道了这世界上存在dp的优化这样的说法,了解了四边形优化dp,所以今天顺带做一道典型的斜率优化,在百度打斜率优化dp,首先弹出来的就是下面这个网址:http://www.cnblogs. ...

  3. hdu 3507 Print Article(斜率优化DP)

    题目链接:hdu 3507 Print Article 题意: 每个字有一个值,现在让你分成k段打印,每段打印需要消耗的值用那个公式计算,现在让你求最小值 题解: 设dp[i]表示前i个字符需要消耗的 ...

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

    Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  5. HDU3507 Print Article —— 斜率优化DP

    题目链接:https://vjudge.net/problem/HDU-3507 Print Article Time Limit: 9000/3000 MS (Java/Others)    Mem ...

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

    题意:需要打印n个正整数,1个数要么单独打印要么和前面一个数一起打印,1次打印1组数的代价为这组数的和的平方加上常数M.求最小代价. 思路:如果令dp[i]为打印前i个数的最小代价,那么有 dp[i] ...

  7. Print Article /// 斜率优化DP oj26302

    题目大意: 经典题 数学分析 G(a,b)<sum[i]时 a优于b G(a,b)<G(b,c)<sum[i]时 b必不为最优 #include <bits/stdc++.h& ...

  8. HDU3507 Print Article (斜率优化DP基础复习)

    pid=3507">传送门 大意:打印一篇文章,连续打印一堆字的花费是这一堆的和的平方加上一个常数M. 首先我们写出状态转移方程 :f[i]=f[j]+(sum[i]−sum[j])2 ...

  9. 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 ...

随机推荐

  1. Django的文件下载

    在实际的项目中很多时候需要用到下载功能,如导excel.pdf或者文件下载,当然你可以使用web服务自己搭建可以用于下载的资源服务器,如nginx,这里我们主要介绍django中的文件下载. 我们这里 ...

  2. 删除Git服务器文件但是保留本地文件

    参考: https://blog.csdn.net/u012804886/article/details/83059315 https://www.cnblogs.com/wfsovereign/p/ ...

  3. Centos7自动式脚本搭建jumpserver

    JumpServer脚本 这里需要安装阿里的yum源和epel源并解压: epel源地址https://mirrors.tuna.tsinghua.edu.cn/epel// 安装阿里互联网yum仓库 ...

  4. openstack——neutron网络服务

    一.neutron 介绍:   Neutron 概述 传统的网络管理方式很大程度上依赖于管理员手工配置和维护各种网络硬件设备:而云环境下的网络已经变得非常复杂,特别是在多租户场景里,用户随时都可能需要 ...

  5. C语言中的DEBUG

    #cat aa.c #include <stdio.h> #include <stdarg.h> #include <stdlib.h> #include < ...

  6. hbase + phoenix 单机版安装

    1. 环境: centos 6.5 jdk 1.8.0                                                 http://www.oracle.com/te ...

  7. python运算符及优先级

    计算机可以进行的运算有很多种,可不只加减乘除这么简单,运算按种类可分为算数运算.比较运算.逻辑运算.赋值运算.成员运算.身份运算.位运算. 一.算数运算 以下假设变量:a=10,b=20 二.比较运算 ...

  8. 【模板】可持久化Treap

    洛谷3835 #include<cstdio> #include<algorithm> #include<cstdlib> #define ls (a[u].l) ...

  9. BZOJ 1452 Count 【模板】二维树状数组

    对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...

  10. 实现selenium+Chrome爬取时不加载图片——配置

    # -*- coding:utf-8 -*- from selenium import webdriver ''' 设置页面不加载图片,这样可以加快页面的渲染,减少爬虫的等待时间,提升爬取效率 固定配 ...