hdu 5586(最大连续子序列和)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586

官方题解:

A i =f(A i )A i  ,然后求一遍最大连续子序列和就能知道最多能增加的值。  

PS:感觉这题好巧妙啊。。很难想到去利用最大连续子序列和求增量。。

#include 
#include 
#include 
using namespace std;

typedef long long LL;
const int maxn = 1e5+5;
const int mod = 1e4+7;
int arr[maxn], data[maxn];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        LL sum = 0;
        for(int i=0; i Max)
                Max = tmp;
            if(tmp < 0)
                tmp = 0;
        }
        LL ret = sum + Max;
        printf("%I64d\n",ret);
    }
    return 0;
}


你可能感兴趣的:(dp,BestCoder,dp)