当前位置:网站首页>7-3 maximum sub segment and
7-3 maximum sub segment and
2022-06-24 23:31:00 【White -】
7-3 Maximum sub sum
Given n It's an integer ( It could be negative ) The sequence of components a[1],a[2],a[3],…,a[n], Find the sequence as a[i]+a[i+1]+…+a[j] The maximum value of the sum of the subsegments of . When all given integers are negative , Define sub segments and as 0.
The time complexity of the algorithm is required to be O(n).
Input format :
There are two lines of input :
The first line is n value (1<=n<=10000);
The second line is n It's an integer .
Output format :
Output maximum sub segment sum .
sample input :
Here's a set of inputs . for example :
6
-2 11 -4 13 -5 -2
sample output :
Here is the corresponding output . for example :
20
Code :
#include <stdio.h>
#include <stdlib.h>
int n;
int a[10100];
int vis[10100];
int findmax(int a,int b)
{
return a>=b?a:b;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int max1=0;
int temp;
for(int i=1;i<=n;i++)
{
if(temp>max1)
max1=temp;
if(temp<0)
temp=a[i];
else
temp+=a[i];
}
printf("%d",max1);
return 0;
}
202206222059 3、 ... and
边栏推荐
- golang map clear
- InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
- 中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
- Spark's wide dependence and narrow dependence yyds dry goods inventory
- RT-thread使用rt-kprintf
- Redis source code analysis skip list
- File contains vulnerability issues
- Still using simpledateformat for time formatting? Be careful of project collapse
- Blogs personal blog test point (manual test)
- 六大行数据治理现状盘点:治理架构、数据标准与数据中台(2022.04)
猜你喜欢
![[basic knowledge] ~ half adder & full adder](/img/06/7f1ede65dca527c8630285b587a4ba.png)
[basic knowledge] ~ half adder & full adder

慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan

Blogs personal blog test point (manual test)

Design and practice of vivo server monitoring architecture

Jetpack Compose 最新进展

Helix distance of point

go 语言指针,值引用和指针引用

Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine

华为机器学习服务语音识别功能,让应用绘“声”绘色
随机推荐
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
Laravel study notes
当初吃土建起来的“中台”,现在为啥不香了?
376. machine tasks
379. 捉迷藏
Use of types, values, namespaces, combinations, etc. in typescript
[basic knowledge] ~ half adder & full adder
From client to server
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the AIC function to compare the AIC values of the two models (simpl
378. 骑士放置
Huawei machine learning service speech recognition function enables applications to paint "sound" and color
文件包含漏洞问题
R language uses the aggregate function of epidisplay package to split numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and customi
File contains vulnerability issues
Bubble sort
R language dplyr package group_ By function and summarize_ The at function calculates the dataframe to calculate the number of counts and the mean value of different groups (summary data by category v
HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
376. 機器任務