1007 Maximum Subsequence Sum (25分)

从生成到检测:全面解析Deepfake技术的演进与对抗策略 本文全面解析了Deepfake技术的演进与对抗策略,从GAN生成技术到先进的检测手段,探讨了其在娱乐与安全领域的双重影响。文章详细介绍了Deepfake的核心原理、技术迭代关键节点以及最新的检测方法,揭示了AI生成与识别的激烈博弈。同时,展望了量子计算和生物特征认证在未来攻防战中的潜在应用。 阅读详情

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

OpenClaw人人养虾:接入Matrix Matrix 是一个开放的去中心化通讯协议(Decentralized Communication Protocol),任何人都可以搭建自己的 Homeserver(家服务器)并与全球 Matrix 网络互联。OpenClaw 通过 Matrix Client-Server API 实现接入。 阅读详情

相关推荐

CISSP/CCSP证书到手后别松懈!保姆级维持攻略:CPE积分怎么攒?年费怎么交?

本文为CISSP/CCSP持证者提供详细的维持认证攻略,重点介绍如何高效积累CPE积分和避免年费缴纳中的常见问题。通过免费与付费资源结合的策略,帮助持证者轻松完成年度认证要求,同时利用认证创造职业价值。

weixin_30859423的博客 416

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

ANSYS APDL齿轮建模实战:从渐开线方程到完整3D模型的保姆级教程

本文详细介绍了使用ANSYS APDL进行齿轮建模的全过程,从渐开线方程的数学基础到完整3D模型的创建。通过参数化命令流实现高精度齿轮建模,特别适合机械设计和仿真分析需求。教程包含关键参数计算、APDL环境配置、单齿齿廓建模以及全齿轮阵列复制等实用技巧,帮助工程师快速掌握ANSYS APDL在齿轮建模中的应用。

lg888的博客 446

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

ubuntu安装glibc

VSCode 在ubuntu下调试无法打开libc-start.c raise.c等1. 安装glibc2. launch.json中添加路径映射3. 调试 1. 安装glibc apt install glibc-source cd /usr/src/glibc/ sudo tar -xvf glibc-[VERSION].tar.xz 2. launch.json中添加路径映射 "sourceFileMap": { "/build/glibc-S7xCS9": "/usr/src/glib

wq_0708的博客 3万+

Rstudio安装org.Hs.eg.db

自己也是个小白,初次安装org.Hs.eg.db碰到好多问题,步骤总结如下: 第一,instal.packages()安装,不行则换 BiocManager::install() 第二,如BiocManager不成,说明不是最新版本,可按提示安装最新版 BiocManager::install(version = '3.13') #由于R版本较新,按照提示中的相关信息,安装最新版本的 第三,再次安装 BiocManager::install("org.Hs.eg.db") 第四,之后每个人.

ZH_DDong的博客 2万+

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

相机中的归一化实现讲解

本分讲解了图像处理中常出现的两个相机归一化操作

weixin_42102084的博客 1475

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

产品缺陷检测:表面缺陷检测_(1).产品缺陷检测基础理论

确定像素之间的相似性准则,如灰度值的差异。

zhubeibei168的博客 832

QT+OSG/osgEarth编译之七十六:gltf+Qt编译(一套代码、一套框架,跨平台编译,版本:osgEarth-3.3插件库osgdb_gltf)

通过一套gltf代码和框架,实现osgdb_gltf跨平台编译。 在Qt环境下,集成头文件、库文件,构建跨平台编译的pro文件。 通过构建的一套配置工程,基于Qt Creator IDE,完成跨平台的编译实践。 在Windows、Linux、MacOS等操作系统上进行测试,成功编译,形成的成果(头文件、库文件等)可在不同系统下调用或使用,从而更好地构建跨平台解决方案。 采用的是osgEarth3.3版本。 读者可参考博客中的集成原理,构建不同版本的osgdb_gltf跨平台包。

LuckyHanMo的博客 1801

【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

对CryptoDriver里密钥格式定义的探索(1)

一入网络安全才发现深似海,传统汽车MCU码农转型之路异常艰难。在CP AUTOSAR中的CryptoDriver SWS对密钥格式的需求来源于RFC,其中要求了RSA、ECC、SHE等key material的格式。再往下看,我就有些迷糊了,例如关于RSA Private Key的OCTEE STRING格式根据IETF RFC8017,Public Key又得根据RFC5280,完全不得其解。所以今天先从生成密钥对,并对其进行解析开始,一步一步拆解。

认真搞搞汽车MCU 527

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

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

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

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

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

NTscan扫描工具

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

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、付费专栏及课程。

余额充值