蛮力法求最大子段
package
com.chen.main;
import java.util.Date;
public class Max ... {
public static void main(String arg[])...{
int[] number=new int[]...{1,-2,3,-4,-8};
int len=number.length;
Date date=new Date();
System.out.println(date.getTime());
int temp=number[0];
int result=number[0];
for(int i=0;i<len-1;i++)...{
for(int j=i+1;j<len;j++)...{
temp+=number[j];
if(temp>result)...{
result=temp;
}
}
temp=number[i+1];
if(temp>result)...{
result=temp;
}
}
System.out.println("最大子段和为:"+result);
Date date2=new Date();
System.out.println(date2.getTime());
System.out.println(date2.getTime()-date.getTime());
}
}
import java.util.Date;
public class Max ... {
public static void main(String arg[])...{
int[] number=new int[]...{1,-2,3,-4,-8};
int len=number.length;
Date date=new Date();
System.out.println(date.getTime());
int temp=number[0];
int result=number[0];
for(int i=0;i<len-1;i++)...{
for(int j=i+1;j<len;j++)...{
temp+=number[j];
if(temp>result)...{
result=temp;
}
}
temp=number[i+1];
if(temp>result)...{
result=temp;
}
}
System.out.println("最大子段和为:"+result);
Date date2=new Date();
System.out.println(date2.getTime());
System.out.println(date2.getTime()-date.getTime());
}
}