zoukankan      html  css  js  c++  java
  • Bzoj2037: [Sdoi2008]Sue的小球

    题面

    传送门

    Sol

    就相当于从(x_0)开始左右横走,显然可以设(f[0/1][i][j])表示左到(i)右到(j),当前在左/右的代价
    但是不好记转移代价,因为不知道时间
    那么可以把它变成最小损失,每次转移就是加上两边没走的蛋降落的损失,最后用总代价相减即可

    # include <bits/stdc++.h>
    # define RG register
    # define IL inline
    # define Fill(a, b) memset(a, b, sizeof(a))
    using namespace std;
    typedef long long ll;
    const int _(1010);
    const ll INF(1e18);
    
    IL ll Read(){
        RG ll x = 0, z = 1; RG char c = getchar();
        for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
        for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
        return x * z;
    }
    
    int n, x0;
    struct Egg{
    	ll x, y, v;
    	IL bool operator <(RG Egg B) const{  return x < B.x;  }
    } w[_];
    ll f[2][_][_], sum[_], s;
    
    int main(RG int argc, RG char* argv[]){
    	n = Read(); x0 = Read();
    	for(RG int i = 1; i <= n; ++i) w[i].x = Read();
    	for(RG int i = 1; i <= n; ++i) w[i].y = Read();
    	for(RG int i = 1; i <= n; ++i) w[i].v = Read();
    	w[++n] = (Egg){x0, 0, -INF}; sort(w + 1, w + n + 1);
    	for(RG int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (w[i].v == -INF ? 0 : w[i].v), s += w[i].y;
    	for(x0 = 1; x0 <= n; ++x0) if(w[x0].v == -INF) break;
    	Fill(f, 63); f[0][x0][x0] = f[1][x0][x0] = 0;
    	for(RG int len = 1; len < n; ++len)
    		for(RG int l = max(1, x0 - len); l <= x0; ++l){
    			RG int r = l + len; if(r > n) break;
    			f[0][l][r] = min(f[0][l][r], f[0][l + 1][r] + (sum[l] + sum[n] - sum[r]) * (w[l + 1].x - w[l].x));
    			f[0][l][r] = min(f[0][l][r], f[1][l + 1][r] + (sum[l] + sum[n] - sum[r]) * (w[r].x - w[l].x));
    			f[1][l][r] = min(f[1][l][r], f[0][l][r - 1] + (sum[l - 1] + sum[n] - sum[r - 1]) * (w[r].x - w[l].x));
    			f[1][l][r] = min(f[1][l][r], f[1][l][r - 1] + (sum[l - 1] + sum[n] - sum[r - 1]) * (w[r].x - w[r - 1].x));
    		}
    	printf("%.3lf
    ", 1.0 * (s - min(f[0][1][n], f[1][1][n])) / 1000);
        return 0;
    }
    
    
  • 相关阅读:
    读《程序是怎样跑起来的》第七章有感
    读《程序是怎样跑起来的》第六章有感
    读《程序是怎样跑起来的》第五章有感
    读《程序是怎样跑起来的》第四章有感
    读《程序是怎样跑起来的》第三章有感
    读《怎样成为一个高手 183》有感
    读《程序是怎样跑起来的》第二章有感
    《程序是怎样跑起来的》第一章读后感
    我与计算机
    师生关系
  • 原文地址:https://www.cnblogs.com/cjoieryl/p/8319819.html
Copyright © 2011-2022 走看看