●HDU 3507 Print Article
题链:





#include<cstdio>
#include<cstring>
#include<iostream>
#define MAXN 500050
using namespace std;
int DP[MAXN],SUM[MAXN];
int N,M;
int dx(int a,int b){
return 2*(SUM[a]-SUM[b]);
}
int dy(int a,int b){
return (DP[a]+SUM[a]*SUM[a])-(DP[b]+SUM[b]*SUM[b]);
}
int main(){
static int q[MAXN],l,r;
while(~scanf("%d%d",&N,&M)){
for(int i=1;i<=N;i++)
scanf("%d",&SUM[i]),SUM[i]+=SUM[i-1];
l=1; r=1; q[1]=0;
for(int i=1;i<=N;i++){
while(l+1<=r&&dy(q[l+1],q[l])<=SUM[i]*dx(q[l+1],q[l])) l++;
DP[i]=DP[q[l]]+(SUM[i]-SUM[q[l]])*(SUM[i]-SUM[q[l]])+M;
while(l+1<=r&&dy(i,q[r])*dx(q[r],q[r-1])<=dy(q[r],q[r-1])*dx(i,q[r])) r--;
q[++r]=i;
}
printf("%d\n",DP[N]);
}
return 0;
}
●HDU 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(CDQ分治+分治DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3507 [题目大意] 将长度为n的数列分段,最小化每段和的平方和. [题解] 根据题目很容易得到dp ...
- [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 —— 斜率优化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 ...
- HDU 3507 Print Article(斜率优化DP)
题目链接 题意 : 一篇文章有n个单词,如果每行打印k个单词,那这行的花费是,问你怎么安排能够得到最小花费,输出最小花费. 思路 : 一开始想的简单了以为是背包,后来才知道是斜率优化DP,然后看了网上 ...
随机推荐
- spring mvc 整合Quartz
Quartz是一个完全由java编写的开源作业调度框架.不要让作业调度这个术语吓着你.尽管Quartz框架整合了许多额外功能, 但就其简易形式看,你会发现它易用得简直让人受不了!Quartz整合在sp ...
- HP DL380服务器RAID信息丢失数据恢复方法和数据恢复过程分享
[数据恢复故障描述] 客户服务器属于HP品牌DL380系列,存储是由6块73GB SAS硬盘组成的RAID5,操作系统是WINDOWS 2003 SERVER,主要作为企业部门内部的文件服务器来 ...
- ASP.NET MVC中错误处理方式
/// <summary> /// 标记了HandleError,并指明错误处理页为AboutError.aspx /// </summary> /// <returns ...
- volt问题
1./表示当前目录:/college/detail/{{ item.sid }}表示这个路径超链接,url实在不好写就不写,作为开发人员想怎么弄就怎么弄最后发布是项目主管的事 2.不需要服务器给值,直 ...
- 《深入实践Spring Boot》阅读笔记之三:核心技术源代码分析
刚关注的朋友,可以回顾前两篇文章: 基础应用开发 分布式应用开发 上篇文章总结了<深入实践Spring Boot>的第二部分,本篇文章总结第三部分,也是最后一部分.这部分主要讲解核心技术的 ...
- emqtt 试用(一)安装和测试
一.安装 http://emqtt.io/docs/v2/getstarted.html http://emqtt.io/docs/v2/advanced.html http://emqtt.io/d ...
- 开源软件:NoSql数据库 - 图数据库 Cassandra
转载原文:http://www.cnblogs.com/loveis715/p/5299495.html Cassandra简介 在前面的一篇文章<图形数据库Neo4J简介>中,我们介绍了 ...
- SpringCloud的注解:EnableEurekaClient vs EnableDiscoveryClient
What's the difference between EnableEurekaClient and EnableDiscoveryClient? In some applications, I ...
- SpringCloud是什么?
参考链接: http://blog.csdn.net/forezp/article/details/70148833 一.概念定义 Spring Cloud是一个微服务框架,相比Dubbo ...
- ABP CORE 框架入门视频教程《电话薄》基于 Asp.NET Core2.0 EF Core
ABP框架简介 ABP是"ASP.NET Boilerplate Project (ASP.NET样板项目)"的简称. ASP.NET Boilerplate是一个用最佳实践和流行 ...