OpenJudge_P1481 Maximum sum(最大双子序列和)
来源:互联网 发布:最准的现货指标源码 编辑:程序博客网 时间:2024/04/29 02:03
总时间限制: 1000ms 内存限制: 65536kB
描述
Given a set of n integers: A={a1, a2,…, an}, we define a function d(A) as below:
Your task is to calculate d(A).
输入
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.
输出
Print exactly one line for each test case. The line should contain the integer d(A).
样例输入
1
10
1 -1 2 2 3 -3 4 -4 5 -5
样例输出
13
提示
In the sample, we choose {2,2,3,-3,4} and {5}, then we can get the answer.
Huge input,scanf is recommended.
来源
POJ Contest,Author:Mathematica@ZSU
第一眼看去就是初赛题
m计算没有初始化成INT_MIN,初始化成0,无限WA
#include<cstdio>#include<cstring>#include<climits>#include<iostream>using namespace std;#define N 50005int t,n,ans,temp,m;int a[N],f1[N],f2[N];int main(){ scanf("%d",&t); while(t--){ memset(f1,0,sizeof(f1));memset(f2,0,sizeof(f2)); scanf("%d",&n);temp=0,m=ans=INT_MIN; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++){ temp+=a[i];if(temp>m) m=temp; if(temp<0) temp=0; f1[i]=m; } temp=0,m=INT_MIN; for(int i=n;i>=1;i--){ temp+=a[i];if(temp>m) m=temp; if(temp<0) temp=0; f2[i]=m; } for(int i=1;i<n;i++){ ans=max(ans,f1[i]+f2[i+1]); } printf("%d\n",ans); } return 0;}
- OpenJudge_P1481 Maximum sum(最大双子序列和)
- [洛谷P2642]双子序列最大和
- poj-2479求最大子序列和(双子序列…
- PAT 1007. Maximum Subsequence Sum (25) 最大子序列和
- poj 2479 Maximum sum (子序列和最大问题)
- 【动态规划(最大子序列和)】:poj2479,Maximum sum
- Maximum Sum 最大子矩阵和+dp+(最大连续子序列的变形)
- 关于最大连续子序列和的问题 (Maximum Subsequence Sum Problem)
- dynamic programming 之Maximum Sub-Sequence Sum(最大子序列和问题)
- 【PAT】1007 Maximum Subsequence Sum (25) 最大连续子序列和 +记录位置
- 动态规划之递增子序列最大和(Maximum Sum Increasing Subsequence)
- 1007. Maximum Subsequence Sum (25) 求最大连续子序列和
- [PAT甲级]1007. Maximum Subsequence Sum(求连续最大子序列和)
- uva108 - Maximum Sum(最大和)
- uva108 Maximum sum(矩阵最大和)
- UVA108 - Maximum Sum(最大连续和)
- ural 1146 Maximum Sum 最大连续和
- poj-2479 Maximum sum 【最大字串和】
- memcached
- 在建好的项目中加入CoreData
- Android开发笔记(八)神奇的shape
- android-service服务
- 创建文件夹
- OpenJudge_P1481 Maximum sum(最大双子序列和)
- DbUtils源码解析
- SVN 一次性提交多个目录中文件的方法
- SpringMVC Maven项目 java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServle
- 使用CAAnimationGroup组合关键帧动画,设置delegate,造成VC无法释放问题
- 动态最小生成树
- XXX.axf: Error: L6218E: Undefined symbol xxx (referred from xxxx.o).
- Windows 平台上的使用 Python 语言实现 appium 自动化程序 for Android(完整版)
- Android SDK 开发范例大全 ---3.10不同Activity之间的数据传递