51nod 1049 最大子段和
来源:互联网 发布:java线程池状态 编辑:程序博客网 时间:2024/06/06 03:43
51nod 1049 最大子段和
动态规划思想:当前最大子段和是前一个数字结尾的子段和(正数)+当前值,子段和(负数)另起子段。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>#include <map>using namespace std;#define INF 0x3f3f3f3f#define PI acos(-1.0)#define mod 10007#define N 110000int n;int main(){ scanf("%d",&n); int a; long long ans = 0; long long now = 0; for(int i = 0 ;i < n; i++) { scanf("%d",&a); if(now < 0) now = a; else now += a; if(now > ans) ans = now; } printf("%lld\n",ans); return 0;}
0 0
- 51nod 1049 最大子段和
- 51Nod 1049 最大子段和
- 51nod:1049 最大子段和
- 51Nod--1049最大子段和
- 51nod 1049 最大子段和
- 51nod 1049 最大子段和
- 51nod 1049 最大子段和
- 51Nod 1049 最大子段和
- 【51nod】1049 最大子段和
- 51NOD 1049 最大子段和
- 51Nod 1049 最大子段和
- 51nod 1049 最大子段和
- 51Nod 1049 最大子段和
- 51Nod 1049 最大子段和
- 51Nod-1049-最大子段和
- 51Nod 1049 最大子段和
- 51Nod-1049 最大子段和
- 51nod--1049 最大子段和
- Linux笔记--vim的基本常用操作总结
- 思维导图复习强化数据结构(持续更新)
- npm之小菜鸟的探索
- ZX 123
- unexpected-top-level-exception
- 51nod 1049 最大子段和
- android ASM 屏幕监视
- shell编程相关内容
- Codeforces Problem 713A Sonya and Queries(字典树)
- Perl 字符串截取函数substr
- C++ Socket编程步骤
- STL
- JS中string方法中常用方法之四:String.fromCharCode()
- 算法篇——快速幂