POJ 2593 Max Sequence
来源:互联网 发布:php常用函数200个 编辑:程序博客网 时间:2024/06/05 18:05
Max Sequence
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 17678 Accepted: 7401
Description
Give you N integers a1, a2 ... aN (|ai| <=1000, 1 <= i <= N).
You should output S.
You should output S.
Input
The input will consist of several test cases. For each test case, one integer N (2 <= N <= 100000) is given in the first line. Second line contains N integers. The input is terminated by a single line with N = 0.
Output
For each test of the input, print a line containing S.
Sample Input
5-5 9 -5 11 200
Sample Output
40
Source
POJ Monthly--2005.08.28,Li Haoyuan
题解:这个题2479差不多,具体可以看2479的题解,不过感觉这道题的测试数据要比2479弱一些,轻松AC
//主要是刷几道dp练练手
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 1e6+7, inf = -1e9+7;int a[maxn], ls[maxn], rs[maxn], rst[maxn], s;int main(){ int n; while (~scanf("%d", &n) && n) { for (int i=0; i<n; i++) scanf("%d", &a[i]); ls[0] = a[0], rs[n-1] = rst[n-1] = a[n-1], s = inf; for (int i=1; i<n; i++) ls[i] = max(ls[i-1]+a[i], a[i]); for (int i=n-2; i>=0; i--) rs[i] = max(rs[i+1]+a[i], a[i]), rst[i] = max(rst[i+1], rs[i]); for (int i=1; i<n; i++) s = max(s, ls[i-1]+rst[i]); printf("%d\n", s); } return 0;}
0 0
- POJ 2593 Max Sequence
- poj 2593 max sequence
- POJ 2593 Max Sequence
- POJ 2593 Max Sequence
- POJ 2593&&2479:Max Sequence
- poj 2593Max Sequence【dp】
- DP专题3 POJ 2593 Max Sequence
- POJ 2593 Max Sequence 解题报告
- poj 2593 Max Sequence(预处理dp)
- POJ 2479 Maximum sum (同POJ 2593 Max Sequence)
- poj 2479 Maximum sum poj 2593 Max Sequence
- poj 2479 Maximum sum && poj 2593 Max Sequence
- POJ 2479 Maximum sum POJ 2593 Max Sequence
- POJ 2479 Maximum sum && POJ 2593 Max Sequence
- poj 2593 Max Sequence( 最大子段和 )
- nyoj 174Max Sequence&poj 2593(dp)
- ACM POJ 2593 Max Sequence ----最大子段和问题
- POJ 2479 Maximum sum && 2593 Max Sequence (dp)买一送一
- 算法导论LUP分解
- Opencv4Android的OpenCL的测试,使用Opencv的ocl封装库
- Pat 1002 数字分类Java解法
- C++11 STL函数 UnorderedSet
- Spring的HibernateTemplate用法
- POJ 2593 Max Sequence
- 1093. Count PAT's (25)[数学逻辑题]
- address
- 你好,世界!
- lucene(补充QueryParser,Filter,高亮显示,近实时搜索)
- 【安卓开发艺术探索】第15章 性能优化、内存泄漏 笔记
- XMLHttpRequest对象(简称XHR)兼容处理
- 【CHROME开发者工具的小技巧】
- Activity之四大启动模式