A two-dimensional array to find the largest subarray

Source: Internet
Author: User

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;j

5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.