question:Super Jumping! Jumping! Jumping!

杭电oj 1087——super jump!jump!jump(java实现)-LMLPHP

意思就是找一串数字中的和最大子串

思路:创建另一个数组,每一项是路径数组对应项之前最大子串的和,然后遍历此数组找出最大值即可(也是参考了别人的博客,下面是链接,这是接触的第一道dp题,希望慢慢的自己也会写!)

原文链接

source code:

package hduoj;

import java.util.Scanner;

public class hdoj_1087 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
int count = sc.nextInt();
if(count==0) break;
int[] path = new int[count];
for(int i = 0;i<count;++i){
path[i] = sc.nextInt();
}
int[] each_maxmium = new int[count];
each_maxmium[0] = path[0];
for(int i = 1;i<count;++i){
each_maxmium[i] = path[i];
for(int j = 0;j<i;++j){
if(path[j]<path[i]&&each_maxmium[i]<path[i] + each_maxmium[j]){//两个条件保证递增以及each_maxmium数组每一项是最大
each_maxmium[i] = path[i] + each_maxmium[j];
}
}
}
int max = -1;
for(int i = 0;i<each_maxmium.length;++i){
if(each_maxmium[i]>max){
max = each_maxmium[i];
}
}
System.out.println(max); } }
}

代码已经ac

希望对大家有所帮助

以上

05-11 19:58