最大子序列之和
来源:互联网 发布:淘宝店主风怎么调色 编辑:程序博客网 时间:2024/05/16 05:13
求数组中最大连续子序列之和。
eg,输入一行数据 1 3 -2 4 -5
输出最大连续子序列和 6
import java.util.*;public class test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); ArrayList<Integer> list = new ArrayList<Integer> (); while(in.hasNext()){ list.add(in.nextInt()); } int len = list.size(); int max ,maxhere; max = maxhere = list.get(0); for(int i = 1; i < len; i++){ if(maxhere <= 0) maxhere = list.get(i); else maxhere += list.get(i); if(maxhere > max){ max = maxhere; } } in.close(); System.out.println(max);
}}
阅读全文
0 0
- 最大子序列之和
- 最大子序列之和
- 最大子序列之和
- 最大子序列之和问题
- 求最大子序列之和
- 最大连续子序列之和
- 求最大子序列之和
- 求最大子序列之和
- 最大连续子序列之和
- 最大连续子序列之和
- 最大连续子序列之和
- 最大连续子序列之和
- 最大子连续序列之和
- 最大连续子序列之和
- 最大连续子序列之和,最大连续子序列乘积
- 计算最大连续子序列之和
- 输出最大连续子序列之和
- 最大的子序列之和问题
- Java好还是Python好
- OpenShift使用笔记
- linux学习中碰到的问题
- IOS 微信聊天发送小视频
- php项目登陆功能
- 最大子序列之和
- markdown编译器的使用指南相对照
- 排序算法实现总结
- 求整数序列的最大子列和
- hdu1008 Elevator
- MySQL主从复制
- 哈工大和中科院的文本处理系统
- 史上最简单的 MySQL 教程(二十八)「外键(上)」
- Java/Android 设计模式系列(1)--单例模式