最大连续子序列 HDU
来源:互联网 发布:php是什么意思在奶粉中 编辑:程序博客网 时间:2024/04/28 19:03
Given a sequence a1 1,a2 2,a3 3......an n, your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.
25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5
Case 1:14 1 4Case 2:7 1 6
#include <iostream>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <algorithm>#include <vector>#include <string>#include <cstring>#include <sstream>#define INF 100000000using namespace std;int a[100005];int main(){ int T; int kase=1; scanf("%d",&T); while(T--) { if(kase!=1) printf("\n"); printf("Case %d:\n",kase++); int tmp=0; int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int maxx=-9999999; int b=0,e=0,l=0; for(int i=0;i<n;i++) { tmp+=a[i]; if(tmp>maxx) { maxx=tmp; e=i; b=l; } if(tmp<0) { tmp=0; l=i+1; } } printf("%d %d %d\n",maxx,b+1,e+1); } return 0;}
0 0
- hdu 最大连续子序列
- HDU最大连续子序列
- 最大连续子序列 HDU
- 最大连续子序列 HDU
- hdu 1231 最大连续子序列 【最大连续子串】
- Hdu 最大连续子序列(DP)
- hdu 1231 最大连续子序列
- hdu 1231 最大连续子序列
- hdu 1231 最大连续子序列和
- hdu 1231 最大连续子序列(DP)
- HDU-1231 最大连续子序列
- HDU 1231 最大连续子序列 (dp)
- HDU 1231 最大连续子序列
- hdu 1231最大连续子序列 【DP】
- hdu 1231 最大连续子序列
- hdu 1231 最大连续子序列
- HDU 1231 最大连续子序列
- hdu 1231 最大连续子序列
- git上使用markDown记录
- Rxjava学习项目_1
- python报数退出圈子,问哪一号最后留下来
- 第八周:100. Same Tree
- C++模板
- 最大连续子序列 HDU
- 【问题收录】Ubuntu14.04出现循环登录无法进入图形界面的问题
- MongoDb安装教程
- 图的最小生成树prim算法总结
- 线上问题的解决思路
- openresty解析php
- 教程:提取macOS应用图标
- 数据驱动决策的13种思维方式
- C#读取Esri Grid删格文件的的办法