HDU 3507 Print Article
来源:互联网 发布:试玩软件赚钱 编辑:程序博客网 时间:2024/05/18 01:39
#include <cstdio>#include <cstring>#define maxn 500005#define inf 0xffffffint dp[maxn];int Q[maxn];int sum[maxn];int get1(int i){ return dp[i]+sum[i]*sum[i];}int get2(int i,int j){ return sum[i]-sum[j];}bool check1(int p,int q,int i){ if((get1(q)-get1(p))<=2*sum[i]*get2(q,p)) return 1; return 0;}bool check2(int p,int q,int i){ if((get1(i)-get1(q))*get2(q,p)<=(get1(q)-get1(p))*get2(i,q)) return 1; return 0;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { int i; int c; for(sum[0]=0,i=1;i<=n;i++) { scanf("%d",&c); sum[i]=sum[i-1]+c; } for(i=1;i<=n;i++) dp[i]=inf; dp[0]=0; int head,tail; head=tail=0; Q[tail++]=0; for(i=1;i<=n;i++) { while(head+1<tail&&check1(Q[head],Q[head+1],i)) head++; dp[i]=dp[Q[head]]+(sum[i]-sum[Q[head]])*(sum[i]-sum[Q[head]])+m; while(head+1<tail&&check2(Q[tail-2],Q[tail-1],i)) tail--; Q[tail++]=i; } printf("%d\n",dp[n]); } return 0;}
0 0
- hdu-3507-Print Article
- hdu 3507 Print Article
- hdu 3507 Print Article
- HDU 3507 Print Article
- 【HDU 3507】 Print Article
- hdu 3507Print Article
- hdu-3507 Print Article
- HDU 3507 Print Article
- HDU 3507 Print Article
- HDU 3507 Print Article
- Print Article[HDU 3507]
- HDU 3507 Print Article
- hdu 3507 Print Article
- hdu 3507 Print Article
- Hdu-3507 Print Article
- HDU 3507 Print Article
- [HDU 3507] Print Article
- hdu 3507 Print Article
- 学习C专家编程笔记(1)
- sql中的连接
- HDU 2829 Lawrence
- daning links 系列
- linux shell命令之find命令
- HDU 3507 Print Article
- 自由市场经济、社会主义和大数据
- NSComboBox 使用方法
- android程序启动画面之Splash总结
- MySQL 索引原理解析
- 去掉String中的空格
- POJ 3017 Cut the Sequence
- mtk6572 映像烧录
- 数据库--sqlserver--sqlserver 查询 值如果为NULL则显示0-解决方法