[ACMcoder] Max Sum

简介: 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

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 caseCount, numCount;
    int caseIndex, numIndex;
    cin>>caseCount;
    for (caseIndex = 1; caseIndex <= caseCount; caseIndex++)
    {
        cin>>numCount;
        int num;
        int local_max = 0;
        int global_max = 0x80000000;
        int start, end;
        int temp = 1;
        for (numIndex = 1; numIndex <= numCount; numIndex++)
        {
            cin>>num;
            local_max += num;
            if (local_max > global_max)
            {
                global_max = local_max;
                start = temp;
                end = numIndex;
            }

            if (local_max < 0)
            {
                local_max = 0;
                temp = numIndex + 1;
            }
        }

        cout<<"Case "<<caseIndex<<":"<<endl;
        cout<<global_max<<" "<<start<<" "<<end<<endl;
        if (caseIndex != caseCount)
            cout<<endl;
    }
}
目录
相关文章
|
存储 人工智能 安全
数据治理:强化数据安全与隐私保护的基石
在当今这个数字化时代,数据已成为推动社会进步和企业发展的核心驱动力。从个人消费习惯到企业运营策略,从政府决策支持到科研创新突破,数据无处不在,其价值不言而喻。然而,随着数据量的爆炸性增长和流通范围的扩大,数据安全与隐私保护问题也日益凸显,成为制约数据价值最大化利用的重要瓶颈。因此,构建完善的数据治理体系,特别是强化数据安全与隐私保护,成为了时代发展的必然要求。
1349 5
|
缓存 前端开发 JavaScript
DolphinScheduler教程(04)- 项目配置分析
DolphinScheduler教程(04)- 项目配置分析
1287 0
DolphinScheduler教程(04)- 项目配置分析
|
1天前
|
人工智能 自然语言处理 JavaScript
2026年Windows+Ollama本地部署OpenClaw保姆级教程:本地AI Agent+阿里云上快速搭建
2026年OpenClaw凭借本地部署、私有化运行的特性,成为打造个人智能体的核心工具,而Ollama作为轻量级本地大模型管理工具,能让OpenClaw摆脱对云端大模型的依赖,实现**本地推理、数据不泄露、全流程私有化**的智能体验。本文基于Windows 11系统,从硬件环境准备、Ollama安装与模型定制、OpenClaw部署配置、技能扩展到常见问题排查,打造保姆级本地部署教程,同时补充阿里云OpenClaw(Clawdbot)快速部署步骤,兼顾本地私有化需求与云端7×24小时运行需求,文中所有代码命令均可直接复制执行,确保零基础用户也能快速搭建属于自己的本地智能体。
2892 12
|
12天前
|
人工智能 自然语言处理 监控
OpenClaw skills重构量化交易逻辑:部署+AI全自动炒股指南(2026终极版)
2026年,AI Agent领域最震撼的突破来自OpenClaw(原Clawdbot)——这个能自主规划、执行任务的智能体,用50美元启动资金创造了48小时滚雪球至2980美元的奇迹,收益率高达5860%。其核心逻辑堪称教科书级:每10分钟扫描Polymarket近千个预测市场,借助Claude API深度推理,交叉验证NOAA天气数据、体育伤病报告、加密货币链上情绪等多维度信息,捕捉8%以上的定价偏差,再通过凯利准则将单仓位严格控制在总资金6%以内,实现低风险高频套利。
6451 58
|
8天前
|
存储 人工智能 负载均衡
阿里云OpenClaw多Agent实战宝典:从极速部署到AI团队搭建,一个人=一支高效军团
在AI自动化时代,单一Agent的“全能模式”早已无法满足复杂任务需求——记忆臃肿导致响应迟缓、上下文污染引发逻辑冲突、无关信息加载造成Token浪费,这些痛点让OpenClaw的潜力大打折扣。而多Agent架构的出现,彻底改变了这一现状:通过“单Gateway+多分身”模式,让一个Bot在不同场景下切换独立“大脑”,如同组建一支分工明确的AI团队,实现创意、写作、编码、数据分析等任务的高效协同。
2877 27
|
30天前
|
人工智能 自然语言处理 Shell
🦞 如何在 OpenClaw (Clawdbot/Moltbot) 配置阿里云百炼 API
本教程指导用户在开源AI助手Clawdbot中集成阿里云百炼API,涵盖安装Clawdbot、获取百炼API Key、配置环境变量与模型参数、验证调用等完整流程,支持Qwen3-max thinking (Qwen3-Max-2026-01-23)/Qwen - Plus等主流模型,助力本地化智能自动化。
43648 157
🦞 如何在 OpenClaw (Clawdbot/Moltbot) 配置阿里云百炼 API
|
4天前
|
人工智能 JavaScript API
2026年Windows系统本地部署OpenClaw指南:附阿里云简易部署OpenClaw方案,零技术基础也能玩转AI助手
在AI办公自动化全面普及的2026年,OpenClaw(原Clawdbot、Moltbot)凭借“自然语言指令操控、多任务自动化执行、多工具无缝集成”的核心优势,成为个人与轻量办公群体打造专属AI助手的首选。它彻底打破了传统AI“只会对话不会执行”的局限——“手”可读写本地文件、执行代码、操控命令行,“脚”能联网搜索、访问网页并分析内容,“大脑”则可灵活接入通义千问、OpenAI等云端API,或利用本地GPU运行模型,真正实现“聊天框里办大事”。
1001 2
|
2天前
|
人工智能 JSON JavaScript
手把手教你用 OpenClaw + 飞书,打造专属 AI 机器人
手把手教你用 OpenClaw(v2026.2.22-2)+ 飞书,10分钟零代码搭建专属AI机器人!内置飞书插件,无需额外安装;支持Claude等主流模型,命令行一键配置。告别复杂开发,像聊同事一样自然对话。
1029 5
手把手教你用 OpenClaw + 飞书,打造专属 AI 机器人