链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003

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

简单的动态规划,最大子串和;

/********* hdu 1003 ************/
/********* 琴心&剑胆 ************/
/********* 2011/5/9 ************/

#include<stdio.h>
int main(){
int T;
scanf( "%d",&T );
int M=T;
while( T-- ){
int n;
scanf( "%d",&n );
int a[n],ts=0,ti=0,s=0,bi=0,bj=n-1,f=0,max=-32767,mi;
for( int i=0;i<n;++i ){
scanf( "%d",&a[i] );
if(max<a[i]){
max=a[i];
mi=i;
}
if( a[i]<0 )
f++;
ts+=a[i];
if(ts<0){
ts=0;
ti=i+1;
}
if(s<ts){
s=ts;
bj=i;
bi=ti;
}
}
printf("Case %d:\n",M-T);
if( f==n )
printf( "%d %d %d\n",max,mi+1,mi+1 );
else
printf( "%d %d %d\n",s,bi+1,bj+1 );
if( T )
printf("\n");
}
}

转载于:https://www.cnblogs.com/jian1573/archive/2011/05/09/2041504.html

hdu 1003 Max Sum 解题报告相关推荐

  1. HDU.1003 Max Sum

    原题 HDU.1003 Max Sum 分类 动态规划 题意 计算从一个序列中最大连续子序列和.对应的起始元素和终止元素的位置. 输入/输出 要求与格式 样例数的确定 最开始一行开始输入样例数 每个样 ...

  2. hdu 1003 Max Sum (DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others)   ...

  3. [hdu 1003] Max Sum

    跟<算法导论(第三版)>上的一样,抄下来的 30 - 60 ms 标准的分治策略 1 #include <stdio.h> 2 3 int A[100000], Lenght; ...

  4. hdu 1003 Max Sum

    DP可以这里给出非DP程序 题目传送门 1 #include<stdio.h> 2 int main() 3 { 4 int t,n,i,max,m,sum,ki,kj,k,a,b; 5 ...

  5. HDU 1003——Max Sum(动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目大意:历遍所有数字,找出最大字段和. 解题思路: t和n:记录循环次数和每一段有多少个数字 ...

  6. 位置子段最大子段和 hdu 1003 max sum ACM的开始

    每日一贴,今天的内容关键字为位置子段 这个标题的印象是较比刻深的,我的第一个动态规划标题,也是ACM的开始.最大字段和是较比经典的动归问题.求一个列序的最大子段和的关键点就在于断判一个元素的归属问题, ...

  7. 杭电OJ——ACM 1003.Max Sum

    Max Sum 杭电OJ--ACM 1003.Max Sum链接入口 问题描述 大意:        给定一个序列a[1],a[2],a[3]-a[n],你需要算出其子序列中的最大值.比如说:给你一个 ...

  8. HDU 1244 Max Sum Plus Plus Plus

    虽然这道题看起来和 HDU 1024  Max Sum Plus Plus 看起来很像,可是感觉这道题比1024要简单一些 前面WA了几次,因为我开始把dp[22][maxn]写成dp[maxn][2 ...

  9. HD 1003 Max Sum (最大字段和问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem Description Given a sequence a[1],a[2],a ...

最新文章

  1. 个人站立会议(11月16日)
  2. 360安全卫士电脑版_卸载360安全卫士!保护你的电脑安全
  3. 火狐浏览器中打开java_Ubuntu下通过Firefox Opera Chromium浏览器直接执行java应用程序(打开java jnlp文件)实现在服务器远程虚拟控制台完成远程管理的方法...
  4. 【Numpy入门实例:图像的手绘效果】
  5. iframe父元素获取子页面的元素
  6. MySQL 的三个自问自答
  7. 学习笔记——C语言打印日志封装
  8. STATA 生存分析cox 等比例风险假设
  9. 条件极值(拉格朗日乘数法)_Simplelife_新浪博客
  10. 全息存储:名气大于实力的存储技术?
  11. MarkDown中输入数学公式
  12. 匹夫细说Unity3D(一)——移动平台动态读取外部文件全解析
  13. Oracle PrimaveraUnifier成本管理器(Cost Manager)简要介绍
  14. html如实现留言板功能,JS实现留言板功能
  15. 深耕细作数据的宇宙魔方:集中化、全流程数据运营管理
  16. Redis有哪些阻塞点以及如何解决?
  17. qemu-system-riscv64 源码编译 及 运行参数
  18. 智子社区顾问白硕:区块链宜从金融“主战场”周边做起
  19. Docker面试相关内容--2022年总结
  20. angular JS + PrimeNG 初学使用

热门文章

  1. matlab 2012 vs2010混合编程
  2. MATLAB2013a的license过期的解决办法
  3. Linux学习笔记-题记
  4. 3.3. shutdown
  5. MySQL和Oracle中的隐式转换
  6. 软件开发和产品经理到底是怎么回事
  7. Java常用的技术网站
  8. 编译可在Android上运行的qemu user mode
  9. finally块中的代码一定会执行吗?
  10. 转 关于 D3D的 SetRenderState 以及AlphaBlend 和AlphaTest