Maximum sum

总Time Limit: 1000msMemory Limit: 65536kB
Description
Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:
            t1     t2 
d(A) = max{ ∑ai + ∑aj | 1 <= s1 <= t1 < s2 <= t2 <= n }
            i=s1   j=s2
Your task is to calculate d(A).
Input
The input consists of T(<=30) test cases. The number of test cases (T) is given in the first line of the input. 
Each test case contains two lines. The first line is an integer n(2<=n<=50000). The second line contains n integers: a1, a2, ..., an. (|ai| <= 10000).There is an empty line after each case.
Output
Print exactly one line for each test case. The line should contain the integer d(A).
Sample Input
1
10
1 -1 2 2 3 -3 4 -4 5 -5
Sample Output
13
Hint
In the sample, we choose {2,2,3,-3,4} and {5}, then we can get the answer
Huge input,scanf is recommended.
求两块最大的互不相交的字序列的和f[i]表示以i结尾的最大子序列的和ff[i]表示i之前的最大子序列的和g[i]表示以i开头的最大子序列的和gg[i]表示i之后的最大子序列的和

max=ff[i]+gg[i+1];

code:
var t:longint;init:array[1..50000]of longint; ii,i,j,k,n:longint; f,g,ff,gg:array[1..50000]of longint; max:longint; max1,max2:longint; function findmax(x,y:longint):longint; begin if x>y then exit(x) else exit(y); end; begin readln(t); for ii:=1 to t do begin readln(n); for i:=1 to n do read(init[i]); f[1]:=init[1]; ff[1]:=f[1]; max1:=f[1]; for i:=2 to n do begin f[i]:=findmax(f[i-1],0)+init[i]; if f[i]>max1 then max1:=f[i]; ff[i]:=max1; end; g[n]:=init[n]; gg[n]:=init[n]; max2:=gg[n]; for i:=n-1 downto 1 do begin g[i]:=findmax(g[i+1],0)+init[i]; if g[i]>max2 then max2:=g[i]; gg[i]:=max2; end; max:=-maxlongint; for i:=1 to n-1 do if max<ff[i]+gg[i+1] then max:=ff[i]+gg[i+1]; writeln(max); end; end.

转载于:https://www.cnblogs.com/spiderKK/p/4928469.html

NOIP前夕:noi.openjudge,Maximum sum相关推荐

  1. 简单英文题 16 Maximum Sum Not Exceeding K(python)

    http://noi.openjudge.cn/english/16/ """ 简单英文题 16 Maximum Sum Not Exceeding K(AC) http ...

  2. D28:Maximum sum(最大和,翻译)

    原题:OpenJudge - 1481:Maximum sum 翻译: 描述:给定一组n个整数:A={a1,a2,...,an},我们定义函数d(A)如下: t1 t2 d(A) = max{ ∑ai ...

  3. 英语翻译 Maximum sum

    OpenJudge - 1481:Maximum sum 2022 2.10 Given a set of n integers: A={a1, a2,..., an}, we define a fu ...

  4. URAL 1146 Maximum Sum(最大子矩阵的和 DP)

    Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...

  5. [Swift]LeetCode1031. 两个非重叠子数组的最大和 | Maximum Sum of Two Non-Overlapping Subarrays...

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  6. NOI openjudge 6043:哆啦A梦的时光机(双向宽搜)

    在线评测: http://noi.openjudge.cn/ch0407/6043/ 整体思路: 这种题随便宽搜一下就好了,没啥思路可讲,,,, 失误之处: 1.开始脑子里想的是一面扩展一层,这样子可 ...

  7. NOI OpenJudge 2722 和数

    2722:和数 描述 给定一个正整数序列,判断其中有多少个数,等于数列中其他两个数的和. 比如,对于数列1 2 3 4, 这个问题的答案就是2, 因为3 = 2 + 1, 4 = 1 + 3. 输入 ...

  8. SPOJ KGSS Maximum Sum (线段树)

    SPOJ KGSS Maximum Sum 题意:求区间最大值与第二大值之和 思路:线段树维护两个最大值 /********************************************** ...

  9. NOIP前夕:noi.openjudge,滑雪

    滑雪 总Time Limit: 1000msMemory Limit: 65536kB Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须 ...

最新文章

  1. python打开中文文本utf-8用不了_关于Python文档读取UTF-8编码文件问题
  2. Linux系统关闭或重新启动主机的命令详解
  3. C# WPF MVVM模式Prism框架从零搭建(经典)
  4. 有的人走着走着就散了!
  5. HDOJ 2639 Bone Collector II (背包)
  6. 第一节:setTimeout和setInterval定时器
  7. javascript无限弹窗_解决下javascript无限弹窗的问题
  8. 陈俊龙:从深度强化学习到宽度强化学习—结构,算法,机遇及挑战
  9. 经过20天的面试终于进了阿里(分享面试过程)
  10. 为什么中国人少有人得到诺贝尔奖呢?
  11. 我们不应该歧视任何的编程语言,因为他们都是萌娘
  12. 单元素/组件的过渡以及过渡钩子的运用
  13. DNS 解析器(DNS Resolver)
  14. 2021/8/12 网络机顶盒
  15. 《东周列国志》第五十二回 公子宋尝鼋构逆 陈灵公衵服戏朝
  16. 微信小程序接入富文本编辑
  17. 市场调研-全球与中国FPGA和CPLD开发套件市场现状及未来发展趋势
  18. ICLR2020国际会议焦点论文(Spotlight Paper)列表(内含论文源码)
  19. 互联网日报 | 6月21日 星期一 | 小米成立手机电影工作室;每日优鲜零售云业务正式亮相;高德打车上线助老暖心车站...
  20. adt linux 离线安装包,ADT离线安装

热门文章

  1. 如何用最短的时间学会C语言,并掌握C语言的精髓所在?
  2. 绑定dictionary 给定关键字不再字典中_对字典嵌套的理解及二级下拉菜单的制作...
  3. python中函数的定义实例_Python基础之函数的定义与使用实例
  4. echarts怎么保存图片到剪切板上_在电脑上怎么批量给图片编号以及怎么自动记录记事本txt文档时间...
  5. convert.todatetime指定日期格式_SQL基础知识V2——常用日期函数
  6. [渝粤教育] 广东-国家-开放大学 21秋期末考试财务管理10164k2 (3)
  7. 21秋期末考试工商企业文化10631k2
  8. 【渝粤题库】陕西师范大学292961 会计学 作业 (高起专)
  9. zigbee物联网模块标准:LTE标准Cat.1和nbiot无线通信模块差异
  10. linux gdb网络调试工具,Linux--gdb调试工具