POJ 2479(2段连续子序列和)
来源:互联网 发布:育才行知小学对口初中 编辑:程序博客网 时间:2024/06/05 10:59
题目要求两段子序列和
分段就行 O(n)
话说这回数组又开小了,居然提示Runtime Error
Program P2479;var t,n,i,j,m,m2,p:longint; a,b,c:array[0..50000] of longint;begin read(t); a[0]:=-100001; while (t>0) do begin read(n); j:=0; m:=0; for i:=1 to n do begin read(a[i]); if a[i]<0 then inc(j); if a[i]>a[m] then m:=i; end; if j>n-2 then begin p:=a[m]; m2:=0; for i:=1 to n do if (i<>m) and (a[m2]<a[i]) then m2:=i; inc(p,a[m2]); writeln(p); end else begin p:=0; m:=-100001; for i:=1 to n do begin inc(p,a[i]); if (p<0) then p:=0; if m<p then m:=p; b[i]:=m; end; p:=0; m:=-100001; for i:=n downto 1 do begin inc(p,a[i]); if (p<0) then p:=0; if m<p then m:=p; c[i]:=m; end; m:=0; for i:=1 to n-1 do if m<b[i]+c[i+1] then m:=b[i]+c[i+1]; writeln(m); end; dec(t); end;end.
- POJ 2479(2段连续子序列和)
- poj 2479 两段连续子序列的最大和
- POJ 2593(最大2连续子段和)
- poj 2479 最大连续子段和 dp算法
- HDU 1231 最大连续子序列(最大连续子段和)
- POJ 1050 To the Max && POJ 2479Maximum sum(DP最大连续子段和)
- HDU1231 最大连续子序列【最大子段和+DP】
- Luogu-p1115最大子段和(连续子序列最大和)
- hdu 1231 最大连续子序列(最大子段和)
- hdu 1231 最大连续子序列(最大子段和)
- poj 3061(连续子序列问题)
- POJ 2479 两段最大子序列
- 最大连续子段和(hdu1003)
- poj 2479 dp Maximum sum求两段连续不重叠子段的最大和
- 最大连续子段和
- 最大连续子段和
- 最大连续子段和
- 最大连续子段和
- 编程之美3.6 扩展
- poj 2983 Is the Information Reliable?
- OPPO Finder超薄设计体验:6.65mm不是极限
- java web 学习
- 网站打开速度优化:如何提高网页加载速度,提升网页打开速度
- POJ 2479(2段连续子序列和)
- 误差扩散算法
- Java字符编码总结
- ATL产生的RGS文件介绍
- [Linux][2012-08-06] 1 字节对齐
- jsoup select 选择器
- lotus中对(热点)功能的使用(解决按钮的问题)
- easyUI SearchBox
- Oracle PL/SQL中如何使用%TYPE和%ROWTYPE 转载自(王朝网络 wangchao.net.cn)