zoukankan      html  css  js  c++  java
  • _bzoj1911 [Apio2010]特别行动队【斜率优化dp】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1911

    裸的斜率优化dp。

    #include <cstdio>
    
    const int maxn = 1000005;
    
    int n, a, b, c, s[maxn], head, tail;
    char ch;
    long long f[maxn];
    struct point {
    	long long x, y;
    	int id;
    } que[maxn], tem;
    
    inline void readint(int & rt) {
    	while ((ch = getchar()) < 48);
    	rt = ch - 48;
    	while ((ch = getchar()) > 47) {
    		rt = rt * 10 + ch - 48;
    	}
    }
    inline long long poww(long long aa) {
    	return aa * aa;
    }
    
    int main(void) {
    	//freopen("in.txt", "r", stdin);
    	readint(n);
    	scanf("%d%d%d", &a, &b, &c);
    	for (int i = 1; i <= n; ++i) {
    		readint(s[i]);
    		s[i] += s[i - 1];
    	}
    	int j;
    	que[tail++] = (point){0, 0, 0};
    	for (int i = 1; i <= n; ++i) {
    		while (tail - head > 1 && que[head].y - que[head + 1].y < 2 * a * s[i] * (que[head].x - que[head + 1].x)) {
    			++head;
    		}
    		j = que[head].id;
    		f[i] = f[j] + a * poww(s[i] - s[j]) + b * (long long)(s[i] - s[j]) + c;
    		tem = (point){s[i], f[i] + a * poww(s[i]) - b * (long long)s[i], i};
    		while (tail - head > 1 && (tem.y - que[tail - 1].y) * (que[tail - 1].x - que[tail - 2].x) > (que[tail - 1].y - que[tail - 2].y) * (tem.x - que[tail - 1].x)) {
    			--tail;
    		}
    		que[tail++] = tem;
    	}
    	printf("%lld
    ", f[n]);
    	return 0;
    }
    

      

  • 相关阅读:
    C 指针运算 指针访问数组
    C 字符串操作函数
    C putchar getchar
    C语言 指向函数的指针变量基础
    Openstack L2GW Plugin installation
    nova + ironic node
    cgroup
    ironic pxe tftp(二)Permission denied
    ironic bind port neutron port
    Failed to start OpenBSD Secure Shell server
  • 原文地址:https://www.cnblogs.com/ciao-sora/p/6371746.html
Copyright © 2011-2022 走看看