• LuoguP1725 琪露诺 (动态规划)


    (单调队列)(堆) 优化

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    
    #else
    
    #define D_e_Line ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 200007;
    
    int l, r;
    int f[N];
    int a[N];
    int q[N];
    int id[N];
    
    int h = 1, t = 1;
    inline int Position(int x){
    	while(q[t] <= f[x] && t >= h) --t;
    	q[++t] = f[x];
    	id[t] = x;
    	while(q[h] + r < x) ++h;
    	return id[h];
    }
    int main(){
        int n;
        io >> n >> l >> r;
        R(i,0,n){
        	io >> a[i];
        	f[i] = 0xcfcfcfcf;
        }
        f[0] = 0;
        int ans = 0xcfcfcfcf;
        R(i,l,n){
            int j = Position(i - l);
            f[i] = f[j] + a[i];
            if(i >= n - r + 1)
              ans = Max(ans, f[i]);
        }
        
        printf("%d",ans);
        
        return 0;
    }
    
  • 相关阅读:
    day10
    python学习第六天
    Python学习第五天
    python学习第四天第一部分
    python学习第三天第一部分
    python学习第二天第二部分
    python学习第二天第一部分
    崔西凡JavaWeb笔记day13-day15(2016年8月30日22:36:30)
    崔希凡JavaWeb笔记day10~day12(2016年8月22日11:55:20)
    崔希凡-javaWeb-笔记day07-day09(2016年7月26日23:14:40)
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11206721.html
Copyright © 2020-2023  润新知