博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1003 Max Sum (DP)
阅读量:4675 次
发布时间:2019-06-09

本文共 1997 字,大约阅读时间需要 6 分钟。

题目链接:

Max Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 158421    Accepted Submission(s): 37055

Problem 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 #include 
2 #include
3 4 using namespace std; 5 6 struct node 7 { 8 int s,e,smax; 9 } sum[100010];10 11 int main ()12 {13 int t,n,Max,k,j;14 int num[100010];15 while (~scanf("%d",&t))16 {17 int flag=1;18 while (t--)19 {20 21 scanf("%d",&n);22 for (int i=0; i
sum[i-1].smax+num[i])33 {34 sum[i].smax=num[i];35 sum[i].s=i;36 sum[i].e=i;37 }38 else39 {40 sum[i].smax=sum[i-1].smax+num[i];41 sum[i].s=sum[i-1].s;42 sum[i].e=i;43 }44 if (Max

 

 
 

转载于:https://www.cnblogs.com/qq-star/p/4269531.html

你可能感兴趣的文章
Git pull 强制覆盖本地文件
查看>>
android preferenceActivity的用法
查看>>
让Mac也能拥有apt-get类似的功能——Brew
查看>>
Scrapy开发指南
查看>>
暑假集训 || 网络流
查看>>
吉日嘎拉DotNet.BusinessV4.2中的一处bug,及我的修复和扩展
查看>>
JVM学习笔记(一)JDK&JRE&JVM
查看>>
云计算商家必争之地 推荐几款云平台
查看>>
[转]B树(多向平衡查找树)详解
查看>>
深入入门正则表达式(java) - 1 - 入门基础
查看>>
ORACLE表、表分区、表空间的区别
查看>>
2015年创业中遇到的技术问题:21-30
查看>>
北戴河游记
查看>>
Intersecting Lines
查看>>
记忆化搜索=搜索的形式+动态规划的思想(来自百度百科)
查看>>
图 | 为什么存在关于图的研究
查看>>
hdu 1133 Buy the Ticket(递推+精度精算)
查看>>
html5学习笔记(<section>)
查看>>
LeetCode: Add Binary 解题报告
查看>>
网络原理笔记索引
查看>>