当前位置:网站首页>DD1 连续最大和
DD1 连续最大和
2022-07-29 21:49:00 【syc596】
DD1 连续最大和
// import java.util.*;
// public class Main {
// public static void main(String[] args){
// Scanner sc=new Scanner(System.in);
// while(sc.hasNext()){
// int n=sc.nextInt();
// int[] array=new int[n];
// for(int i=0;i<array.length;i++){
// array[i]=sc.nextInt();
// }
// int sum=array[0];
// int max=array[0];
// for(int i=1;i<array.length;i++){
// sum=Math.max(sum+array[i],array[i]);
// if(sum>max){
// max=sum;
// }
// }
// System.out.println(max);
// }
// }
// }
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int[] array=new int[n];
for(int i=0;i<array.length;i++){
array[i]=sc.nextInt();
}
int[] dp=new int[n+1];
dp[0]=array[0];
int max=array[0];
for(int i=1;i<array.length;i++){
dp[i]=Math.max(dp[i-1]+array[i],array[i]);
if(dp[i]>max){
max=dp[i];
}
}
System.out.println(max);
}
}
}边栏推荐
猜你喜欢
随机推荐
刀具更换策略问题(完工)
SwiftUI Apple App Store 发布App的初学者完整指南
"Introduction to nlp + actual combat: Chapter 7: Dataset loading in pytorch and the use of its own datasets"
Xshell 7 提示 “要继续使用此程序,您必须应用最新的更新或使用新版本”
《nlp入门+实战:第七章:pytorch中数据集加载和自带数据集的使用》
SAP BC 源代码搜索
tkinter绘制组件(31)——支点标题
linux install redis using script
九、HikariCP源码分析之ConcurrentBag二
华为畅享50 Pro评测:HarmonyOS加持 更流畅更安全
防火墙——SNAT和DNAT策略的原理及应用、防火墙规则的备份和还原
qt中qstring合并字符串
rtsp-simple-server + srs搭建流媒体服务器
linkedlist的用处之一:通过结构体成员的地址获取结构体变量的地址
GTK进行rgb绘图
GBASE 8s 通过light scan优化查询性能
【Verilog】Verilog设计进阶
lambda expression
毕业论文文献综述写作技巧,超级详细!
GBASE 8s 用户标示与鉴别








![[BUG]一个数组new的时候sizeof()忘乘上个数](/img/d7/fa821aee0626e715bbb4e422e7e2fb.png)
