• poj2479


    与poj2593相同

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 100003

    int f[maxn], fleft[maxn], fright[maxn];
    int n;

    void input()
    {
    for (int i = 0; i < n; i++)
    scanf(
    "%d", &f[i]);
    }

    void work1()
    {
    fleft[
    0] =f[0];
    for (int i = 1; i < n; i++)
    if (f[i] > fleft[i - 1] + f[i])
    fleft[i]
    = f[i];
    else
    fleft[i]
    = fleft[i - 1] + f[i];
    for (int i = 1; i < n; i++)
    fleft[i]
    = max(fleft[i - 1], fleft[i]);
    }

    void work2()
    {
    fright[n
    - 1] =f[n - 1];
    for (int i = n - 2; i >= 0; i--)
    if (f[i] > fright[i + 1] + f[i])
    fright[i]
    = f[i];
    else
    fright[i]
    = fright[i + 1] + f[i];
    for (int i = n - 2; i >= 0; i--)
    fright[i]
    = max(fright[i + 1], fright[i]);
    }

    void work3()
    {
    int ans = -1000000000;

    for (int i = 0; i < n - 1; i++)
    ans
    = max(ans, fleft[i] + fright[i + 1]);
    printf(
    "%d\n", ans);
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    int t;
    scanf(
    "%d", &t);
    while (t--)
    {
    scanf(
    "%d", &n);
    input();
    work1();
    work2();
    work3();
    }
    return 0;
    }

  • 相关阅读:
    《代码大全2》阅读笔记02
    《代码大全2》阅读笔记01
    第二阶段冲刺第六天
    学习进度5
    构建之法阅读笔记03
    地铁进度记录
    学习进度4
    个人数组
    学习进度3
    构建之法阅读笔记02
  • 原文地址:https://www.cnblogs.com/rainydays/p/2052001.html
Copyright © 2020-2023  润新知