20140313
来源:互联网 发布:sql注入 from 编辑:程序博客网 时间:2024/05/21 17:52
package dynamic_programming;class Type {int sum;int begin;int end;Type(int sum, int begin, int end) {this.sum = sum;this.begin = begin;this.end = end;}Type copy() {return this;}}public class DynamicProgramming {public static void main(String[] args) {int[] a = new int[] { -3, 2, 4, 5, -7, -5, 6, 7, 8, -5, 2, 3, -2};System.out.println("数组为:");for(int tem: a)System.out.print(tem + " ");System.out.println();showMax(a);}public static void showMax(int[] n) {int temp = 0;Type type1 = new Type(n[0], 0, 0);Type type2 = new Type(n[0], 0, 0);for (int index = 0; index < n.length; index++) {if (temp < 0) {temp = n[index];if(type2.sum < type1.sum){type2 = type1.copy();}type1 = new Type(n[index], index, index);} else {temp += n[index];}if (type1.sum <= temp) {type1.sum = temp;type1.end = index;} }if(type2.sum < type1.sum){type2 = type1.copy();}System.out.println("开始位置索引:" + type2.begin);System.out.println("结束位置索引:" + type2.end);System.out.println("最大子数组和:" + type2.sum);}}
0 0
- 20140313
- 20140313
- C++学习札记20140313
- 开发笔记之20140313
- 20140313孤独者之旅28
- FZU 1571 排列的字典序问题
- cocos2d-x 2.2 创建项目
- tag 标签开发 note
- 用Android平板与RaspberryPi配置便携物理渗透设备(Pwn Pad & PwnPi)
- smack+openfire插件实现广播。向所有在线用户发送消息。
- 20140313
- struts2 注解的使用
- 两个chrome 同步软件
- 条件编译指令
- 1.PHP内核探索:从SAPI接口开始
- (19)获取根目录
- 给傻瓜用的SP2010开发--第一部分--理解SP开发平台--第一章节--理解SP促销讨论(3)--所以,到底什么是SP呢
- 黑马程序员--java基础--抽象类
- JQuery中extend怎么用