hdu 1003 Max Sum (DP)
题目链接: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): 158421 Accepted Submission(s):
37055
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.
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).
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.
#include <iostream>
#include <cstdio> using namespace std; struct node
{
int s,e,smax;
} sum[]; int main ()
{
int t,n,Max,k,j;
int num[];
while (~scanf("%d",&t))
{
int flag=;
while (t--)
{ scanf("%d",&n);
for (int i=; i<n; i++)
{
scanf("%d",&num[i]);
}
sum[].smax=num[];
sum[].s=sum[].e=;
k=,j=;
Max=sum[].smax;
for (int i=; i<n; i++)
{
if (num[i]>sum[i-].smax+num[i])
{
sum[i].smax=num[i];
sum[i].s=i;
sum[i].e=i;
}
else
{
sum[i].smax=sum[i-].smax+num[i];
sum[i].s=sum[i-].s;
sum[i].e=i;
}
if (Max<sum[i].smax)
{
Max=sum[i].smax;
k=sum[i].s;
j=sum[i].e;
}
}
printf ("Case %d:\n",flag++);
printf ("%d %d %d\n",Max,k+,j+);
if (t)
printf ("\n");
}
}
return ;
}
hdu 1003 Max Sum (DP)的更多相关文章
- HDOJ(HDU).1003 Max Sum (DP)
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...
- hdu 1003 Max sum(简单DP)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- HDU 1003 Max Sum && HDU 1231 最大连续子序列 (DP)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1003 Max Sum(DP)
点我看题目 题意 : 就是让你从一个数列中找连续的数字要求他们的和最大. 思路 : 往前加然后再判断一下就行. #include <iostream> #include<stdio. ...
- hdu 1003 Max Sum(基础dp)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1003 Max Sum【动态规划求最大子序列和详解 】
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1003 Max Sum (动规)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
随机推荐
- 【Linux】- rm命令
Linux rm命令用于删除一个文件或者目录. 语法 rm [options] name... 参数: -i 删除前逐一询问确认. -f 即使原档案属性设为唯读,亦直接删除,无需逐一确认. -r 将目 ...
- C的强制转换和C++的强制转换(转)
C的强制转换: (type)<expression> 其中,type为类型描述符,如int,float等.<expression>为表达式.经强制类型转换运算符运算后,返回一个 ...
- SonarQube安装
要求 至少1G以上内存,推荐为2G Java:Oracle JRE 7u75+,OpenJDK 7u75+ 数据库: Microsoft SQL Server 2008/2012/2014 MySQL ...
- git & configs
git & configs https://alvinalexander.com/git/git-show-change-username-email-address https://stac ...
- windows 架设SVN服务器
想完整走一遍svn布置及使用流程,试完整理了一下: step 1:下载安装 1.安装SVN服务器,到http://subversion.apache.org/packages.html 上下载wind ...
- 【题解】NOIP2015推销员
……普及组的题目都做不出来……(:´д`)ゞ……再这样下去要退役了啊…… 不过不管怎样感觉这题还是蛮好的,也要记录一下下~ 我们注意到数据的范围,n 是 1e5, 又有 1e5组询问,暴力大概是 \( ...
- 原 cocos2dx中毒冰冻shader
#ifdef GL_ES precision mediump float; #endif uniform sampler2D u_texture; varying vec2 v_texCoord; v ...
- BZOJ3223:文艺平衡树——超详细题解
http://www.lydsy.com/JudgeOnline/problem.php?id=3223 题面复制于洛谷. 题目背景 这是一道经典的Splay模板题——文艺平衡树. 题目描述 您需要写 ...
- BZOJ1034 [ZJOI2008]泡泡堂BNB 【贪心】
1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3531 Solved: 1798 [Submit][ ...
- props设置state误区
class Component extends React.Component { constructor(props) { super(props); this.state = { value: t ...