1007 Maximum Subsequence Sum (25分)

UE4动作游戏实例RPG Action解析二:GAS系统播放武器绑定的技能,以及GE效果 官方实例激活技能通过装备系统数据激活,我先用武器数据资产直接激活官方实例蒙太奇播放是自定义的AbilityTask,我先用更简单的方法实现效果1.1.1 插件启用AbilitySystem1.1.2 PlayerCharacter绑定技能组件AbilitySystemComponent 1.1.3 技能初始化,AbilitySystemComponent->GiveAbility 把上节获取到的默认武器绑定的技能GameAbility 添加到ASC组件 1.2、创建一个GameplayAbili 阅读详情

1007 Maximum Subsequence Sum (25分)
Given a sequence of K integers { N​1, N2, …, N​K}. A continuous subsequence is defined to be { N​i, N​i+1, …, N​j} where 1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.

Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.

Input Specification:
Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer K (≤10000). The second line contains K numbers, separated by a space.

Output Specification:
For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices i and j (as shown by the sample case). If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.

Sample Input:
10
-10 1 2 3 4 -5 -23 3 7 -21

Sample Output:
10 1 4

本题直接使用动态规划即可。这里要注意一点,下方程序中我利用变量high来保存最大序列和的下标,然而当n=1时,并不会进入迭代的为dp数组赋值的循环语句,这就导致没有赋初值的变量high用于数组访问,发生段错误。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 10010;
int data[maxn];
int dp[maxn];
int main(){
    int n;
    scanf("%d",&n);
    int flag = 0;
    for(int i=0;i<n;i++){
        scanf("%d",&data[i]);
        if(data[i]>=0) flag = 1;
    }
    if(!flag){
    	printf("0 %d %d",data[0],data[n-1]);
    	return 0;
	}
    sum[0] = data[0];
    int m=-99999,high=0;
	for(int i=1;i<n;i++){
		dp[i] = max(data[i],data[i]+dp[i-1]);
		if(dp[i]>m){
			m = dp[i];
			high = i;
		}
	}
	int res = 0,low=0;
	for(int i=high;i>=0;i--){
		if(res+data[i] == dp[high]){
			low = i;
			break;
		}	
		res+=data[i];
	}
	printf("%d %d %d",dp[high],data[low],data[high]);
    return 0;
}

单智能体篇:Prompt工程艺术 模型在接收到 Prompt 时会自动扮演“角色”,角色定义的好坏直接影响智能体输出的风格和专业性。角色定义的重要性让智能体具备明确身份,例如“你是一位专业理财顾问”或“你是一个幽默的文案创作助手”。角色限定了模型知识输出的范围,使回答更专业、更贴合预期。实战示例模糊Prompt给我一些投资建议。你可以投资股票或者基金。优化Prompt你是一位具有10年经验的专业理财顾问,请给我针对30岁男性,年收入20万,风险偏中等的投资组合建议。 阅读详情

相关推荐

单相全桥逆变器中比例谐振(PR)控制的优化设计与实现

本文深入探讨了比例谐振(PR)控制在单相全桥逆变器中的优化设计与实现。通过对比PID控制,详细阐述了PR控制在50Hz基波频率处实现无静差跟踪和强抗干扰性的原理。文章提供了从理论建模、参数整定(Kp, Kr, ωc)到仿真验证的完整实战流程,并介绍了准比例谐振(QPR)控制以增强频率鲁棒性,以及多谐振点设计以抑制特定谐波等进阶优化方法,最终实现THD从3%降至1%以内的显著性能提升。

weixin_29056781的博客 176

A1007 Maximum Subsequence Sum (25 分)PAT甲级真题(C++)【最大子序列和+动态规划】

Given a sequence ofKintegers {N1​,N2​, ...,NK​}. A continuous subsequence is defined to be {Ni​,Ni+1​, ...,Nj​} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given seq...

qq_47677800的博客 945

Android投屏开发实战:手把手教你用Miracast实现Sink端功能(附完整代码)

本文是一份Android投屏Sink端开发的实战指南,详细讲解了如何利用Miracast协议和Wi-Fi P2P技术,从零构建一个功能完整的屏幕接收器。内容涵盖环境搭建、通过反射启用WFD Sink模式、RTSP协议协商、RTP流接收与解析,以及最终使用IjkPlayer进行音视频解码播放的全过程,并附有核心代码示例。

cherry的博客 878

1007 Maximum Subsequence Sum (25 分)遇到的坑

坑1:注意“ If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.”   如果不注意这个要求,结果应该是这样的: 坑2:其实...

天啊野 8065

光伏储能交直流微电网Matlab/Simulink仿真模型

首先是光伏储能交直流微电网,这个也是我还是之前在硕士期间在做光伏扶贫项目时候搭建的仿真,仿真由光伏、蓄电池及负载组成的独立直流微电网,提出电压和电流分段式协同控制策略。接下来我将主要更新关于光伏、风电、储能微电网系统相关的内容,包括具体建模和控制。

2401_89292556的博客 785

天池长期赛:二手车价格预测(422方案分享)

本次比赛是一次很好的锻炼数据挖掘能力的入门赛,从EDA-数据清洗-特征工程-模型调参-模型融合,能够完整的学习到大数据的分析和挖掘,值得历练。

weixin_46685991的博客 1万+

1007 Maximum Subsequence Sum (25 分)(有坑,最大子段和)

https://pintia.cn/problem-sets/994805342720868352/problems/994805514284679168 Given a sequence ofKintegers {N​1​​,N​2​​, ...,N​K​​}. A continuous subsequence is defined to be {N​i​​,N​i+1​​, ...

永夜莫明的博客 532

B.3【智能标注】:基于Labelstudio的UIE半监督深度学习的智能标注方案(云端版),提效。

Label Studio 所提供的 Machine Learning Backend 提供了一个比较灵活的辅助人工标注的框架,我们通过它确实可以加快 nlp 数据的标注Label Studio 的 enterprise 版本提供了 Active Learning 的流程,不过从其描述看这个流程并不完美,尤其是 fit 部分,由于 Label Studio 低估了「Train」所花费的时间,所以每次标注都自动训练的流程可能并不会那么顺滑(会在链接时候等待一段时间)

丨汀、的博客 1840

pat甲级1007 Maximum Subsequence Sum (动态规划)

1007 Maximum Subsequence Sum (25 分) Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to be { N​i​​, N​i+1​​, ..., N​j​​ } where 1≤i≤j≤K. The Maximum Su...

whisperlzw的博客 286

网络层隧道技术之ICMP隧道(pingTunnel/IcmpTunnel)

目录 ICMP隧道 使用ICMP搭建隧道(PingTunnel) 使用ICMP搭建隧道(Icmptunnel) ICMP隧道 ICMP隧道简单实用,是一个比较特殊的协议。在一般的通信协议里,如果两台设备要进行通信,肯定需要开放端口,而在ICMP协议下就不需要。最常见的ping命令就是利用的ICMP协议,攻击者可以利用命令行得到比回复更多的ICMP请求。在通常情况下,每个ping命令都有相...

谢公子的博客 6696

华为OD机试真题 新系统2026-04-01 C语言 实现【计算数列位置N的值】

1、输入M、N两个数,则按照以下规则形成一个数列; 2、数列的前M个元素的值为1到M; 3、从M+1个元素开始,计算的逻辑为: 如果其前面的M个元素中,存在值相同的元素,则该位置上的数值等于前面M个数中最大的数值与最小的数值之如果其前面的M个元素中,不存在值相同的元素,则该位置上的数值等于前面M个数中最大的数值与最小的数值之差;

MISAYAONE的博客 589

【PAT甲级】1007 Maximum Subsequence Sum (25 分)

Maximum Subsequence Sum 题目描述 Given a sequence of K integers { N​1 , N​2, …, NK }. A continuous subsequence is defined to be { N​i​ , N​i+1​​ , …, Nj​​ } where 1≤i≤j≤K. The Maximum Subsequence is the...

初见还是重逢的博客 392

揭秘CAS:深入理解与应用解析

在并发编程中,Compare-And-Swap(CAS)机制作为一种无锁算法,凭借其高效性和避免线程阻塞的优势,受到广泛关注。CAS不仅在底层实现上有着重要地位,还在实际开发中发挥着关键作用。本文将从CAS的工作原理、在Java中的实现及其增强机制来回顾和加深理解一下CAS。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 85万+

1007 Maximum Subsequence Sum (25 分)

Given a sequence of K integers { N ​1 ​​ , N ​2 ​​ , …, N ​K ​​ }. A continuous subsequence is defined to be { N ​i ​​ , N ​i+1 ​​ , …, N ​j ​​ } where 1≤i≤j≤K. The Maximum Subsequence is the contin...

ftx456789的博客 801

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

1007 Maximum Subsequence Sum (25)(25 分)

1 题目 2 解题思路 3 AC代码 1 题目 Given a sequence of K integers { N~1~, N~2~, …, N~K~ }. A continuous subsequence is defined to be { N~i~, N~i+1~, …, N~j~ } where 1 &lt;= i &lt;= j &lt;= K. The ...

大山喵写博客的地方 975

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

1007 Maximum Subsequence Sum (25 分)

1007 Maximum Subsequence Sum (25 分) Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to be { N​i​​, N​i+1​​, ..., N​j​​ } where 1≤i≤j≤K. The Maximum Su...

A_Bo的博客 504

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

1007  Maximum Subsequence Sum (25分)

Maximum Subsequence Sum Given a sequence ofKintegers {N​1​​,N​2​​, ...,N​K​​}. A continuous subsequence is defined to be {N​i​​,N​i+1​​, ...,N​j​​} where1≤i≤j≤K. The Maximum Subsequence is...

weixin_43850619的博客 488

[PAT] 1007 Maximum Subsequence Sum (25 分)Java

1007 Maximum Subsequence Sum (25 分) Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to be { N​i​​, N​i+1​​, ..., N​j​​ } where 1≤i≤j≤K. The...

Simma1101的博客 274
上一篇: 1105 Spiral Matrix (25分)
下一篇: 深度学习入门:pytorch实战CIFAR10图片分类
一颗橡树
博客等级 码龄8年 23粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值