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 ;
}

最新文章

  1. Particle System(粒子系统)
  2. asp.net 获取汉字字符串的拼音首字母,含多音字
  3. netty研究【1】:编译源代码
  4. bootstrap框架 导航条组件使用
  5. 重新签名IPA ( iPhone )
  6. 用 AIML 开发人工智能聊天机器人
  7. Java中Array的常用方法
  8. IE 8兼容:X-UA-Compatible的解释
  9. AVAudioPlayer音频播放器-备用
  10. Scala学习文档-访问修饰符
  11. 项目 Web 的 NuGet 程序包还原失败: 找不到“1.0.0”版本的程序包“Microsoft.Net.Compilers”。。 0
  12. netty常用使用方式
  13. Two 观察者 observer pattern
  14. C++学习-8
  15. 恶补web之一:html学习(2)
  16. unity协程coroutine浅析
  17. [译]Ocelot - Big Picture
  18. Spvmn测试环境搭建及其安全性讨论
  19. apache_php_mysql
  20. 【Spark2.0源码学习】-7.Driver与DriverRunner

热门文章

  1. sqlserver 创建用户仅仅能訪问指定视图
  2. 项目bug的修正
  3. 【六】注入框架RoboGuice使用:(Singletons And ContextSingletons)
  4. 数据库实例: STOREBOOK &gt; 用户
  5. Android GUI之View事件处理
  6. [JSP]JSP中include指令和include动作的差别
  7. 【Hadoop】Combiner的本质是迷你的reducer,不能随意使用
  8. Inner Classes with TypeScript
  9. isPostback 的原理及作用(很easy)
  10. 安装Ubuntu 桌面版 12.04 LTS 过程之记录