思路:

就是先正常的dp一下求一个最大连续子串,然后特殊情况就是sum-最小连续子串。。

比一比谁大谁小就好了

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std; typedef long long LL; const int N=5e4+10;
const LL INF=5e13+10; LL a[N]; int main()
{
int n;
LL ans1,ans2,sum;
sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
sum+=a[i];
}
LL temp1=a[1];
LL temp2=a[1];
ans2=INF;
ans1=-INF;
for(int i=2;i<=n;i++)
{
if(temp1>0)
temp1+=a[i];
else
temp1=a[i];
if(temp1>ans1)
ans1=temp1; if(temp2<0)
temp2+=a[i];
else
temp2=a[i];
if(temp2<ans2)
ans2=temp2;
}
//printf("%lld %lld\n",ans1,ans2);
printf("%lld\n",max(ans1,sum-ans2));
return 0;
}

51nod 1050【DP】的更多相关文章

  1. 51nod 1354【DP】

    (我一定是A了一题假DP) 给定序列a[0],a[1],a[2],...,a[n-1] 和一个整数K时, 有多少子序列所有元素乘起来恰好等于K. K<=1e8; 思路: 感觉 k 的 约数是突破 ...

  2. 51nod 1154【DP】

    区间DP大暴力吧?GG. dp[ i ] 为字符至 i 的最少数量. 如果[Left , Right]是回文串, dp[Right] = min(dp[ Right ] , dp[Left-1] + ...

  3. 51nod 1268【dp】

    思路: 很水的dp吧...问的都是能否组成.. 哦对,这里sum最大才2e7,不会是2e9所以放心dp #include<cstdio> #include <map> #inc ...

  4. Kattis - honey【DP】

    Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...

  5. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  6. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  7. HDOJ 1257 最少拦截系统 【DP】

    HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  8. HDOJ 1159 Common Subsequence【DP】

    HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  9. HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】

    HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

随机推荐

  1. 配置 yum 源相关

    1. 修改yum配置 http://www.cnblogs.com/shuaixf/archive/2011/11/30/2268496.html 2. centos安装 epel 源 https:/ ...

  2. 修改ubuntu系统时区

    ubuntu默认时区是Etc/UTC,和我们的北京时间相差8个时区,需要修改系统的时区,以下有两种简单方式修改系统时区: 1.修改/etc/timezone文件 vi /etc/timezone 把E ...

  3. HDU 2825 Wireless Password (AC自己主动机,DP)

    pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...

  4. css设置背景图片自适应

      CreateTime--2017年12月25日16:36:07 Author:Marydon 控制背景图片100%自适应填充布局 /* 控制背景图片100%自适应填充布局 */ body{ bac ...

  5. [转载]php中深拷贝浅拷贝

    转自:http://cnn237111.blog.51cto.com/2359144/1283163 PHP中提供了一种对象复制的操作,clone.语法颇为简单: $a = clone $b; 1.浅 ...

  6. [转载]CodeIgniter配置之URL

    应该有很多项目中会有这样的情况,通过 http://pc.local 可以访问,若通过 http://localhost/pc/public 则会出现一些图片.样式显示不到,超链接出错的情况,项目的移 ...

  7. Redis java使用

    直接应用redis.clients:jedis的jar包到项目中,然后直接就可以使用,具体对五种类型的数据操作方法,可以翻代码找到. 连接到 redis 服务 实例 import redis.clie ...

  8. Yarn调度器负载模拟器——Yarn Scheduler Load Simulator (SLS)

    一.概述: Yarn调度器有很多实现,如Fifo, Capacity和Fair schedulers等.与其同一时候,正在进行一些优化措施来提高调度器在不同负载和工作场景下的性能.每一个调度器都有自己 ...

  9. 持续集成-jenkins 环境搭建

    转自:http://blog.jxdev.me/blog/2015/03/26/jian-xin-de-chi-xu-ji-cheng-zhi-lu-%5B%3F%5D-da-jian-jenkins ...

  10. tomcat 部署项目的多种方式

    项目放在tomcat webapps也不会加载两次 下面可以指定项目名称及path   加载war   部署war包  后面不用加war的后缀 <Host appBase="D:/pr ...