zoukankan      html  css  js  c++  java
  • Luogu2858[USACO06FEB]奶牛零食Treats for the Cows (区间DP)

    我是个傻逼,这么水的题都会T

    #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 Abs(a) ((a) < 0 ? -(a) : (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")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #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 = 2007;
    
    int f[N][N], a[N];
    int main(){
    	//FileOpen();
    	
    	int n;
    	io >> n;
    	R(i,1,n){
    		io >> a[i];
    		f[i][i] = a[i] * n;
    	}
    	
    	R(len,2,n){
    		R(l,1,n){
    			int r = l + len - 1;
    			if(r > n) break; // what happend to my mind that I'm dare to write 'continue' !
    			f[l][r] = Max(f[l][r - 1] + a[r] * (n - len + 1), f[l + 1][r] + a[l] * (n - len + 1)); // Shit, I put another for insideeeeeeeeeeeeeeee
    		}
    	}
    	
    	printf("%d
    ", f[1][n]);
    	
    	return 0;
    } 
    

  • 相关阅读:
    模块介绍
    homebrew 更改镜像,进行成功安装
    必须要会的 50 个 React 面试题
    聚合
    mongodb高级聚合查询
    一款好用 mongodb 可视化工具
    在Mac上安装MongoDB,配置全局路径
    深入Vue2.x的虚拟DOM diff原理
    H5在WebView上开发小结
    接口文档RAP2 环境搭建(正常搭建成功)
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11230301.html
Copyright © 2011-2022 走看看