hdu 1003,nefu 728 max sum
Description
Given a sequence a[1],a[2],a[3]......a[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.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with
a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains
three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
Sample Output
Case 1:
14 1 4 Case 2:
7 1 6 //前1个数的DP值>=0,就加;DP值<0,就重新开始,自己本身。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring> using namespace std;
int data[],dp[]; int main()
{
int c,num=,n;
cin>>c;
while(c--)
{
num++;
int maxx=-,a=,b=;
memset(dp,,sizeof(dp));
cin>>n;
for(int i=;i<n;i++)
scanf("%d",&data[i]);
dp[]=data[];
for(int i=;i<n;i++)
{
if(dp[i-]>=)
{
dp[i]=dp[i-]+data[i];
}
else
{
dp[i]=data[i];
a=i;
}
if(dp[i]>maxx)
{
maxx=dp[i];
b=i;
}
}
printf("Case %d:\n",num);
printf("%d %d %d\n",maxx,a+,b+);
}
return ;
}
hdu 1003,nefu 728 max sum的更多相关文章
- hdu 3415(单调队列) Max Sum of Max-K-sub-sequence
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=3415 大意是给出一个有n个数字的环状序列,让你求一个和最大的连续子序列.这个连续子序列的长度小于等于k. ...
- hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- HDU 1003 Max Sum【动态规划求最大子序列和详解 】
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- Max Sum -- hdu -- 1003
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDOJ(HDU).1003 Max Sum (DP)
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...
- hdu 1003 Max Sum (DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1003 Max Sum (动规)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu 1003 Max sum(简单DP)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
随机推荐
- Jquery 操作DropDownList 根据条件选中
$("#<%=DDLCounty.ClientID%> option").each(function () { if ($(this).text() == $(&quo ...
- URL中的#
作者:阮一峰 http://www.ruanyifeng.com/blog/2011/03/url_hash.html 一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如 ...
- hdu1029
#include<iostream>#include<string.h>using namespace std;int main(){ int n,i; int t; int ...
- dplyr 数据操作 常用函数(5)
继续来了解dplyr中的其他有用函数 1.sample() 目的是可以从一个数据框中,随机抽取一些行,然后组成新的数据框. sample_n(tbl, size, replace = FALSE, w ...
- sim808模块收发送短信
一,简介 SIM 808发送短信分text模式和PDU模式.text模式已ascii码发送短信,这种模式比较简单,发送命令AT+CMGF=1就可以发送短信,而PDU模式比较复杂,首先发送命令AT+CM ...
- layer1.8UI
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 8、关于viewWithTag
1.viewWithTag检索tag的方法问题viewWithTag方法会对当前View和其子View进行搜索,查找符合tag的对象,但如果view和其多个子view中都含有相同tag值对象时,该方法 ...
- http请求 302解决方法
http请求+302解决方法 相关文章 当前,许多站点的部署方式都对自身的性能产生了消极影响,而网站的所有者并没有意识到这个问题.我们今天针对性的讨论以下几个常见的影响网站性能的瓶颈,观察其变化趋势, ...
- doT模板
框架源码地址 https://github.com/olado/doT <div id="main"> <script id="banner-templ ...
- WEB 技术分类 Javascript DOM(Element Node) BOM
Web technology for developers Web 技术文档 备注:本文介绍web technology的分类,各自职责,因为之前一直就没有搞明白各种技术.各种名词究竟是属于哪个范 ...