hdu4258 斜率优化dp
来源:互联网 发布:淘宝经营地怎么改 编辑:程序博客网 时间:2024/06/05 05:18
参考下面文章http://blog.csdn.net/balloons2012/article/details/7912296感觉最重要的是 和当前位置有关的斜率,随下表递增单调。。这样凸包才可以求得最优解
</pre><pre name="code" class="cpp">#include <iostream>#include <cmath>#include <cstdio>#define N 1000010#define LL long longusing namespace std;struct point{ LL x, y; point(LL a=0, LL b = 0): x(a), y(b) { } void set(LL a, LL b) { x = a; y = b; }};point que[N];LL a[N];LL dp[N];bool mul(const point &a, const point &b, const point &c) { return (b.x-a.x) * (c.y-a.y) <= (b.y-a.y)*(c.x-a.x); }int main(int argc, char* argv[]) { LL n, c; while(scanf("%lld%lld", &n, &c) && (n && c)) { for(LL i=0; i<n; ++i) { scanf("%lld", &a[i]); } int head = 0, tail = 0; que[tail++].set(a[0], a[0]*a[0]); dp[0] = c; for(LL i=1; i<n; ++i) { point pp(a[i], dp[i-1]+a[i]*a[i]); while(head+1 < tail && mul(que[tail-2], que[tail-1], pp)) --tail; que[tail++] = pp; while(head+1 < tail && que[head].y-2*a[i]*que[head].x >= que[head+1].y-2*a[i]*que[head+1].x) ++head; dp[i] = que[head].y - 2*a[i]*que[head].x + a[i]*a[i] + c; } printf("%lld\n", dp[n-1]); } return 0;}
0 0
- hdu4258 斜率优化dp
- DP(斜率优化)
- 【斜率优化DP】Batch_Scheduling
- dp优化--斜率
- 斜率优化DP
- 斜率优化DP
- hdu3507斜率优化dp
- DP斜率优化总结
- hdu3480 斜率优化dp
- hdu3507 斜率优化dp
- 斜率优化DP
- 斜率优化DP 【pascal】
- 斜率优化DP
- dp 斜率优化
- 斜率优化 DP
- HDU_3669 斜率优化DP
- dp斜率优化
- DP斜率优化
- windows server 2008中安装bitnami-Redmine-3.1.1-1可能遇到的问题
- 九度OJ 1092:Fibonacci (递归)
- 简单配置实现hbase单机模式
- 第四周项目3——单链表应用(2)
- 用switch语句实现多分支结构
- hdu4258 斜率优化dp
- Android ExpandableListView开发简介
- 第7周项目3 - 负数把正数赶出队列
- CV codes代码分类整理合集
- C盘使用内存突然间增加好多
- 排队看病模拟
- 九度OJ 1093:WERTYU (翻译)
- 第七周项目五—排队看病模拟
- 第9周 项目3—稀疏矩阵的三元组表示的实现及应用