HDU Max Sum

简介:

Max Sum

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 191 Accepted Submission(s): 98
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
#include <iostream>
using namespace
 std;
int
 main()
{

    int
 T,N,max,sum,start,end,temp,t;

    cin>>T;
    int
 h = T;
    while
(T--)
    {

        sum = 0;
        start = 1;
        end = 1;
        temp = 1;
        max = -1001;
        cin>>N;
       for
(int i = 1; i <= N; i++)
       {

            cin>>t;
            sum +=t;
            if
(sum>max)
            {

                max = sum;
                end = i;
                start = temp;
            }

            if
(sum<0)
            {

                sum = 0;
                temp = i+1;
            }
       }

       if
(T!=0)

       cout<<"Case "<<h-T<<":"<<endl<<max<<" "
       <<
start<<" "<<end<<endl<<endl;
       else
 cout<<"Case "<<h-T<<":"<<endl<<max
       <<
" "<<start<<" "<<end<<endl;
    }

    return
 0;
}












本文转自NewPanderKing51CTO博客,原文链接:http://www.cnblogs.com/newpanderking/archive/2011/08/03/2125824.html,如需转载请自行联系原作者


相关文章
|
8月前
|
人工智能 运维 架构师
技能革命3.0时代:云计算就业岗位有哪些?
本文探讨云计算就业市场的深层逻辑,从岗位体系、AI赋能及技术局限性应对策略三方面解析。云计算岗位涵盖基础设施、平台服务、数据智能与应用创新四层,需复合型能力;AI不仅提供技术工具,还推动教育范式变革,助力跨界融合;面对技术局限,分步验证与经验洞察双管齐下。未来就业将向技能多元化、自主性增强和社会价值再定义方向进化,强调个体能力生态的持续成长。
|
6月前
|
编译器 程序员 开发者
详解HarmonyOS NEXT系统中ArkTS和仓颉的混合开发
本文介绍了鸿蒙系统中ArkTs与仓颉语言的混合开发方法,讲解了如何通过DevEco Studio创建混合项目、目录结构特点及组件调用方式,强调编译器自动化处理大幅简化开发流程,提升了开发体验。
|
10月前
|
存储 机器学习/深度学习 人工智能
C 408—《数据结构》易错考点200题(含解析)
408考研——《数据结构》精选易错考点200题(含解析)。
1225 27
|
供应链 监控 算法
ERP系统中的库存优化与成本控制解析
【7月更文挑战第25天】 ERP系统中的库存优化与成本控制解析
1341 2
|
机器学习/深度学习 人工智能 算法
后端开发者如何利用AI进行跨学科融合
【6月更文挑战第1天】后端开发者如何利用AI进行跨学科融合
501 6
|
JavaScript
vue uniapp通用省市下拉选择器组件 布局样式可灵活根据ui变更 (区域 可根据数组嵌套的格式继续往下模仿即可)
vue uniapp通用省市下拉选择器组件 布局样式可灵活根据ui变更 (区域 可根据数组嵌套的格式继续往下模仿即可)
886 0
vue uniapp通用省市下拉选择器组件 布局样式可灵活根据ui变更 (区域 可根据数组嵌套的格式继续往下模仿即可)
|
Java 数据库连接 数据库
深入了解Java中的MyBatis Plus注解 @IdType:优雅处理主键生成策略
在数据库表设计中,主键是一项非常关键的概念,而主键生成策略则是决定如何生成主键值的重要环节之一。MyBatis Plus作为一款强大的ORM框架,提供了注解 `@IdType`,使得开发者能够更加灵活地处理主键生成策略,同时降低了代码的冗余度。本文将详细介绍 `@IdType` 注解的用法及其在持久层开发中的应用。
2786 0
|
存储 算法 小程序
通过14个入门实战案例教大家快速学习Python编程语言
欢迎来的我的小院儿,这里会用兴趣编程方法跟大家一起学习编程。通过14个入门实战案例快速学习Python编程语言。跟着我一起学习,不在枯燥,不在孤单......
通过14个入门实战案例教大家快速学习Python编程语言
|
存储 前端开发 生物认证
实现Web端指纹登录(上)
实现Web端指纹登录(上)
实现Web端指纹登录(上)