1. Knot Group members
Zhang Construction, Zhou Hope Super
2. Implement the function
Randomly produces an array of two-dimensional shapes, with positive numbers in the array and negative values. A contiguous sub-matrix in a two-dimensional array consists of a sub-array, each of which has a and. The maximum value for the and of all sub-arrays.
3. Design Ideas
I feel that this should be the stupidest way, we used four for nesting. The idea is simple: each line of each row of the maximum sub-array and is considered to be n one-dimensional sub-array to maximize the sub-array and to record the results, and then the two lines as a row up and down two numbers, each two lines to find the largest sub-array and then three rows, four rows, n rows.
4. Complete code
Package two-dimensional array; import Java.util.random;import Java.util.scanner;public class B {public static void main (string[] args) { TODO auto-generated Method stub int a[][]; int I,j,l,h,n,k,sum,max; Randomly generates an array Scanner Scanner = new Scanner (system.in); System.out.print ("Outputs the length of the randomly generated array:"); H=scanner.nextint (); System.out.print ("Outputs the height of the randomly generated array:"); L=scanner.nextint (); Scanner.close (); A=new Int[l][h]; for (i=0;i<l;i++) {for (j=0;j5. Running Results
6. My Harvest
In this experiment, we have been thinking, discussing, programming, testing. Now the feeling of thinking stage is the most important, we have not come up with any better way, with four for this stupid method simple implementation. But this experiment also has a small harvest, is more familiar with for use, four for nesting is a piece of cake.
A two-dimensional array to find the largest subarray