UVa 11059 最大乘积 java 暴力破解


题目链接:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000


暴力破解


import java.util.Scanner;


public class MaxProduct {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int count ;
int data[];
long a ;
long max ;
while(scan.hasNext()){
max = 0;

count = scan.nextInt();
data = new int[count];
for(int i=0;i<count;i++){
data[i] = scan.nextInt();
}
for(int i=1;i<=count;i++){   //先由不同长度枚举

for(int j = 0;i+j<=count;j++){  //相同的长度根据不同的起点划分
a = 1;
for(int x = j;x<j+i;x++){   //对每个段内进行累乘,将该序列与纪录最大量的变量进行对比,赋值给最大量变量
a *= data[x];
}
max = Math.max(max, a);
}
}
System.out.println(max);
}
}


}
posted @ 2018-02-08 01:20  凌乱533  阅读(107)  评论(0编辑  收藏  举报