zoj1003-Max Sum (最大连续子序列之和)
http://acm.hdu.edu.cn/showproblem.php?pid=1003
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 161361 Accepted Submission(s): 37794
Case 1: 14 1 4
Case 2: 7 1 6
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> using namespace std; #define EPS 1e-10
#define ll long long
#define INF 0x7fffffff int main()
{
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
int T,n,ans,tn,l,r,al,ar,t;
scanf("%d",&T);
for(int tt=;tt<=T;tt++){
scanf("%d",&n);
ans=tn=-INF;
for(int i=;i<=n;i++){
scanf("%d",&t);
if(tn<){
l=r=i;
tn=t;
}else{
tn+=t;
r=i;
}
if(tn>ans){
al=l;
ar=r;
ans=tn;
}
}
printf("Case %d:\n%d %d %d\n",tt,ans,al,ar);
if(tt!=T) puts("");
}
return ;
}
zoj1003-Max Sum (最大连续子序列之和)的更多相关文章
- 杭电1003 Max Sum 【连续子序列求最大和】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max ...
- PAT 1007 Maximum Subsequence Sum (最大连续子序列之和)
Given a sequence of K integers { N1, N2, ..., *N**K* }. A continuous subsequence is defined to be { ...
- hdu1003 Max Sum【最大连续子序列之和】
题目链接:https://vjudge.net/problem/HDU-1003 题目大意:给出一段序列,求出最大连续子序列之和,以及给出这段子序列的起点和终点. 解题思路:最长连续子序列之和问题其实 ...
- [CareerCup] 17.8 Contiguous Sequence with Largest Sum 连续子序列之和最大
17.8 You are given an array of integers (both positive and negative). Find the contiguous sequence w ...
- PAT 1007 Maximum Subsequence Sum 最大连续子序列和
Given a sequence of K integers { N1, N2, …, NK }. A continuous subsequence is defined to be { Ni, Ni ...
- [ACM_动态规划] hdu1003 Max Sum [最大连续子串和]
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...
- [POJ1050]To the Max (矩阵,最大连续子序列和)
数据弱,暴力过 题意 N^N的矩阵,求最大子矩阵和 思路 悬线?不需要.暴力+前缀和过 代码 //poj1050 //n^4暴力 #include<algorithm> #include& ...
- 【动态规划】最大连续子序列和,最大子矩阵和,最大m子段和
1.最大字段和问题 求一个序列最大连续子序列之和. 例如序列[-1,-2,-3,4,5,-6]的最大子段和为4 + 5 = 9. ①枚举法 int MaxSum(int n,int *a){ int ...
- HDU 3415 Max Sum of Max-K-sub-sequence【单调队列】
<题目链接> 题目大意: 给你一段从1~N的圆形序列,要你求出这段圆形序列中长度不超过K的最大连续子序列之和是多少,并且输出这子序列的起点和终点. 解题分析: 既然是求连续子序列之和,我们 ...
随机推荐
- 转载-java基础学习汇总
共2页: 1 2 下一页 Java制作证书的工具keytool用法总结 孤傲苍狼 2014-06-24 11:03 阅读:25751 评论:3 Java基础学习总结——Java对象的序列化和 ...
- Linux 期中架构 SSH
为其他网络服务提供安全协议.替代Telnet SSH: 实现数据加密传输 22 默认支持root用户远程连接 类似sftp-server服务 nmap -p 22 10.0.0.41 nc 10 ...
- tensorflow函数学习:队列和线程
队列函数: FIFOQueue和RandomShuffleQueue 1.FIFOQueue FIFOQueue是先进先出队列,主要针对序列样本.如:使用循环神经网络时,需要处理语音.文字.视频等序列 ...
- Oracle内存详解之二 Library cache 库缓冲-转载
Library cache是Shared pool的一部分,它几乎是Oracle内存结构中最复杂的一部分,主要存放shared curosr(SQL)和PLSQL对象(function,procedu ...
- git 上传本地代码到github 服务器
git init git add . (所有文件用 点表示) git commit -m "注释语句" git remote add origin https://github.c ...
- Spark分析之Master
override def preStart() { logInfo("Starting Spark master at " + masterUrl) webUi.bind() // ...
- Amazon AWS S3 操作手册
Install the SDK The recommended way to use the AWS SDK for Java in your project is to consume it fro ...
- win2008安装IIS
win2008安装IIS http://jingyan.baidu.com/article/fec4bce2398747f2618d8b88.html http://127.0.0.1/ 新建网站,端 ...
- REST 服务器调试 RESTDebugger.exe 和浏览器测试
开发一个简单的rest服务器, 增加了一些函数,比如返回系统当前时间 如何验证是否正确呢,不需要自己编写客户端调用程序了, 可以直接使用RESTDebugger.exe D:\Program File ...
- 使用Teleport Ultra批量克隆网站,使用Easy CHM合并生成chm文件
1.要下载的页面 http://www.howsoftworks.net/javaapi/ 2. 下载Teleport Ultra 3.使用Teleport Ultra批量克隆网站 4.下载Easy ...