zoukankan      html  css  js  c++  java
  • LightOJ 1031 区间dp

    /********************
    
    LightOJ 1031
    
    Author:Cdegree
    
    ********************/
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <cctype>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <map>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <set>
    #define X first
    #define Y second
    #define sqr(x) (x)*(x)
    #pragma comment(linker,"/STACK:102400000,102400000")
    using namespace std;
    const double PI = acos(-1.0);
    map<int, int>::iterator it;
    typedef long long LL ;
    template<typename T> void checkmin(T &x, T y) {x = min(x, y);}
    template<typename T> void checkmax(T &x, T y) {x = max(x, y);}
    
    const int N = 105;
    int a[N], dp[N][N], sum[N];
    int main() {
        int T, n;
        scanf("%d", &T);
        for(int t = 1; t <= T; ++t) {
            scanf("%d", &n);
            memset(dp, 0, sizeof(dp));
            sum[0] = 0;
            for(int i = 1; i <= n; ++i) {
                scanf("%d", a + i);
                dp[i][i] = a[i];
                sum[i] = sum[i-1] + a[i];
            }
            for(int L = 1; L < n; ++L) {
                for(int i = 0; i + L <= n; ++i) {
                    dp[i][i+L] = sum[i+L] - sum[i-1];
                    for(int j = i; j < i + L; ++j) {
                        dp[i][i+L] = max(dp[i][i+L] , sum[j] - sum[i-1] - dp[j+1][i+L]);
                        dp[i][i+L] = max(dp[i][i+L] , sum[i+L] - sum[j] - dp[i][j]);
                    }
                }
            }
            printf("Case %d: %d
    ", t, dp[1][n]);
        }
        return 0;
    }
  • 相关阅读:
    超详细JSON解析步骤
    HTTP请求头和响应头总结
    Oracle 数据库常用操作语句大全
    关于HTTP协议,一篇就够了
    PowerDesigner工具建表步骤
    求助:ACM剑气算法
    一道题
    个人Java学习中的遇到的几个模糊的地方
    Java编程:数学黑洞6174
    高级查询
  • 原文地址:https://www.cnblogs.com/cxw199204/p/3348565.html
Copyright © 2011-2022 走看看