zoukankan      html  css  js  c++  java
  • Luogu1063 能量项链 (区间DP)

    惊恐地发现自己连区间DP都会错2333

    #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 = 1007;
    int a[N], f[N][N];
    
    int main(){
    	//FileOpen();
    	
    	int n;
        io >> n;
        R(i,1,n){
        	io >> a[i];
        	a[i + n] = a[i];
        }
        
        int ans = 0;
        R(len,2,n){
        	R(l,1,n << 1){
        		int r = l + len - 1;
        		if(r > (n << 1)) continue;
        		R(k, l + 1, r){
        			f[l][r] = Max(f[l][r], f[l][k - 1] + f[k][r] + a[l] * a[k] * a[r + 1]);
        			ans = Max(ans, f[l][r]);
        		//1	printf("f %d %d :%d
    ", l, r, f[l][r]);
        		}
        	}
        }
        
        
        printf("%d", ans);
        
    	return 0;
    }
    

  • 相关阅读:
    初识MVC web框架--Controller与View交互1
    Web框架UI系列--MVC常用控件讲解
    管理大师__Vuex
    语言国际化----vue-i18n
    uniapp动态获取高度
    vue__双向数据绑定v-model
    vue__模板解析3一般指令解析
    vue__模板解析2:事件指令解析
    vue__模板解析:大花括号表达式解析
    vue__数据代理
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11228071.html
Copyright © 2011-2022 走看看