HDUOJ--------1003 Max Sum
2024-09-27 01:39:45
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 132258 Accepted Submission(s): 30652
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
Author
Ignatius.L
最大连续和sum....运用动态规划思想
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n,j,i,num,a,ans,maxc,posst,posen,temp;
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&num);
maxc=;
posst=posen=;
ans=-0x3f3f3f3f ;
temp=;
for(j=;j<=num;j++)
{
scanf("%d",&a);
maxc+=a;
if(ans<maxc)
{
ans=maxc;
posen=j;
posst=temp+;
}
if(maxc<)
{
maxc=;
temp=j;
}
}
printf("Case %d:\n%d %d %d\n",i,ans,posst,posen);
if(i!=n) putchar();
}
return ;
}
最新文章
- Particle System(粒子系统)
- asp.net 获取汉字字符串的拼音首字母,含多音字
- netty研究【1】:编译源代码
- bootstrap框架 导航条组件使用
- 重新签名IPA ( iPhone )
- 用 AIML 开发人工智能聊天机器人
- Java中Array的常用方法
- IE 8兼容:X-UA-Compatible的解释
- AVAudioPlayer音频播放器-备用
- Scala学习文档-访问修饰符
- 项目 Web 的 NuGet 程序包还原失败: 找不到“1.0.0”版本的程序包“Microsoft.Net.Compilers”。。 0
- netty常用使用方式
- Two 观察者 observer pattern
- C++学习-8
- 恶补web之一:html学习(2)
- unity协程coroutine浅析
- [译]Ocelot - Big Picture
- Spvmn测试环境搭建及其安全性讨论
- apache_php_mysql
- 【Spark2.0源码学习】-7.Driver与DriverRunner
热门文章
- sqlserver 创建用户仅仅能訪问指定视图
- 项目bug的修正
- 【六】注入框架RoboGuice使用:(Singletons And ContextSingletons)
- 数据库实例: STOREBOOK >; 用户
- Android GUI之View事件处理
- [JSP]JSP中include指令和include动作的差别
- 【Hadoop】Combiner的本质是迷你的reducer,不能随意使用
- Inner Classes with TypeScript
- isPostback 的原理及作用(很easy)
- 安装Ubuntu 桌面版 12.04 LTS 过程之记录