HDOJ 1003
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 85953 Accepted Submission(s): 19912
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 <iostream>
2 using namespace std;
3
4
5 int main()
6 {
7 int numbers;
8 cin>>numbers;
9 for(int k =0;k<numbers;k++)
10 {
11 int num;
12 cin>>num;
13
14
15 int * number = new int [num];
16 int * start = new int [num];
17 int * b = new int [num];
18 for(int i=0;i<num;i++)
19 cin>>number[i];
20
21 b[0]= number[0];
22 start[0]=0;
23 for(int i=1;i<num;i++)
24 {
25 if(b[i-1]+number[i]>=number[i])
26 {
27 b[i]=b[i-1]+number[i];
28 start[i]= start[i-1];
29 }
30 else
31 {
32 b[i]= number[i];
33 start[i]= i;
34 }
35 }
36 int max = b[0];
37 int pos=0;
38 for(int i=0;i<num;i++)
39 {
40 if(b[i]>max)
41 {
42 max=b[i];
43 pos = i;
44 }
45 }
46 cout<<"Case "<<k+1<<":"<<endl<< max<<" "<<start[pos]+1<<" "<<pos+1<<endl;
47 if(k!=numbers-1)
48 cout<<endl;
49 delete number;
50 delete start;
51 delete b;
52
53
54 }
55
56
57 return 0;
58
59
60
61 }
- 程序猿是如何解决SQLServer占CPU100%的
- 记一次SQLServer的分页优化兼谈谈使用Row_Number()分页存在的问题
- 分享一个自制的 .net线程池1
- 分享一个自制的 .net线程池2
- 基于百度翻译的简单爬虫翻译-- coding:utf-8 --访问网址模拟浏览器创建文件夹用一个text文件保存,文件名用单词名字
- .net采集网页方法大全(5种)
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
- 中文分词之结巴分词~~~附使用场景+demo(net)
- 用微信二维码登录自己的网站
- 2620: [Usaco2012 Mar]Haybale Restacking
- 1671: [Usaco2005 Dec]Knights of Ni 骑士
- 1592: [Usaco2008 Feb]Making the Grade 路面修整
- Mysql 该如何 Entity Framework 数据库迁移 和 如何更好的支持EF.Extended
- 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Http:GET和POST请求的区别
- 十六进制数组转换成ASCII码
- 解决ModuleNotFoundError: No module named ‘pip’问题
- 【FreeRTos】队列管理1
- 【FreeRTOS】队列管理2
- ubuntu——Zbar 在linux/ubuntu下的安装编译
- ZBAR库
- 英文文本关系抽取(fine-tune Huggingface XLNet)
- Laravel 7.x 使用 keyspace notification 监听不到 Key 过期事件
- 嵌入式链接脚本(LINK SCRIPT)介绍
- zbar中的zbar_scan_image 函数
- PM2源码分析
- zbar库中的zbar_scan_y函数
- 快速学习-Nacos Config--服务配置
- C 库函数 - fread()