HDU1003 Max Sum(求最大字段和)
事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧!
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
1000).
position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
Case 1:
14 1 4 Case 2:
7 1 6
代码例如以下:
#include <cstdio>
#define INF 0x3fffffff
#define M 100000+17
int a[M];
int main()
{
int n, i, T, k = 0;
while(~scanf("%d",&T))
{
while(T--)
{
scanf("%d",&n);
int s = 1, e = 1, t = 1;
int sum = 0, MAX = -INF;
for(i = 1; i <= n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
if(sum > MAX)
{
s = t;
e = i;
MAX = sum;
}
if(sum < 0)
{
t = i+1;
sum = 0;
}
}
printf("Case %d:\n",++k);
printf("%d %d %d\n",MAX,s,e);
if(T!=0)
printf("\n");
}
}
return 0;
}
HDU1003 Max Sum(求最大字段和)的更多相关文章
- 解题报告:hdu1003 Max Sum - 最大连续区间和 - 计算开头和结尾
2017-09-06 21:32:22 writer:pprp 可以作为一个模板 /* @theme: hdu1003 Max Sum @writer:pprp @end:21:26 @declare ...
- HDU-1003 Max Sum(动态规划,最长字段和问题)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- hdu1003 Max Sum(经典dp )
A - 最大子段和 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descr ...
- ACM学习历程—HDU1003 Max Sum(dp && 最大子序列和)
Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...
- HDU--1003 Max Sum(最大连续子序列和)
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...
- HDU 1003 Max Sum 求区间最大值 (尺取法)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- [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 ...
- 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)
最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...
- hdu1003 Max Sum【最大连续子序列之和】
题目链接:https://vjudge.net/problem/HDU-1003 题目大意:给出一段序列,求出最大连续子序列之和,以及给出这段子序列的起点和终点. 解题思路:最长连续子序列之和问题其实 ...
随机推荐
- jquery ajax跨域的完美解决方法(jsonp方式)
ajax跨域请求的问题,JQuery对于Ajax的跨域请求有两类解决方案,不过都是只支持get方式,接下来为大家详细介绍下客户端JQuery.ajax的调用代码 今天在项目中需要做远程数据加载 ...
- kerboros安装
尽管前面尝试了hadoop的simple认证方式,这种方法不是特别安全,在介绍一下hadoop的kerberos方式之前,下面我们尝试一下kerberos. 首先介绍一下Kerboros安装 OS 版 ...
- Ubuntu关闭图形界面
方法一 sudo /etc/init.d/lightdm stop 方法二 init 3 关闭图形界面 init 5 开启图形界面
- linux下使用libiconv库转码
iconv命令实现linux下字符集编码的转换 windows下的文件复制到linux下时常会乱码,因为windows下文件编码为GBK,linux下默认文件编码为UTF-8,故需要libiconv库 ...
- jq 写法
<!doctype html> <html> <head> <meta charset="utf-8"> <script sr ...
- html5 拖放到购物车
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Supports BorlandIDEServices
Delphi: procedure SetKeystrokeDebugging(Debugging: Boolean); var Dialog: IOTAKeyboardDiagnostics beg ...
- How to run a terminal inside of vim?
[How to run a terminal inside of vim?] :sh turn vim into shell mode d+trl back to vim 参考:http://stac ...
- ASP.NET的分页方法(二)
第二讲主要使用到了常用的分页控件aspnetpager,这里对他就行一个简单的应用,具体大家可以到杨涛的博客上去寻找相关的DLL, 首先要先引用AspNetPager.dll,然后把这个DLL同时添加 ...
- Cocos2d-x 关于在iOS平台真机测试的一些注意
下面简单记录一下在最近cocos2d-x项目在iOS平台真机测试和模拟器测试中遇到的一些要注意的地方(使用ipod): 1.图片大小 游戏中基本上都是会用到图片,那么在使用图片的时候要特别注意图片的s ...