First, the topic requirements
Title: Returns the number of the largest sub-arrays in a two-dimensional integer array.
Requirements: Enter a two-dimensional shape array with positive and negative numbers in the array. 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. Requires a time complexity of O (n).
Pair programming Requirements: The pair completes the programming task. One person is mainly responsible for program analysis, code programming. One person is responsible for code review and Code test plan. Publish a blog post about the process, experience, and how to resolve conflicts between two people (attach a work photo of the development). (As of Thursday April 9 24:00)
Second, the idea of programming
Our thinking is relatively simple, using the sub-matrix and all to find out and then compare the idea of selecting the maximum value. The general idea is determined, mainly how to find out and how to find out each sub-matrix and. Because the process is more troublesome, with the picture to indicate:
Third, the program code
#include <iostream>#include<time.h>using namespacestd;#defineM 3//m number of rows#defineN 3//n Number of columnsvoidMain () {inta[m][n],i,j,b[ -]; Srand ((int) Time (0)); //the value of the array is randomly generated for(i=0; i<m;i++) { for(j=0; j<n;j++) {A[i][j]=-rand ()% $+ -; } } //Display Arraycout<<"The matrix is as follows:"<<Endl; for(i=0; i<m;i++) { for(j=0; j<n;j++) {cout<<a[i][j]<<'\ t'; } cout<<Endl; } intC=0, d,e,f,sum=0, sum1=0; //calculate values for all sub-matrices for(i=0; i<m;i++) { for(f=0; f<n;f++) {sum=0; Sum1=0; for(j=f;j<n;j++) {sum+=A[i][j]; B[C]=sum; C++; Sum1=sum; for(d=i+1;d <m;d++) { for(e=f;e<=j;e++) {sum1+=A[d][e]; } B[c]=sum1; C++; } } } } intMax; Max=b[0]; for(i=0; i<c;i++) { if(b[i]>max) {Max=B[i]; }} cout<<"the value of the maximum sub-matrix of the matrix is:"<<max<<Endl;}
Iv. Results of operation
V. Work photos
Vi. Summary
this time I am mainly responsible for writing code, Connor students responsible for code review and testing. Write code when you want to take a piece of paper to think of any method or ideas to write down, we must first think of logical thinking clearly in the beginning of the compilation, or the loop part of the code is easily confused. In addition to writing, in accordance with the code of the class written, each if or for a statement regardless of the following several statements have to be enlarged brackets, so that looks more clear-looking. This trial writing code is more troublesome, but the code test I feel not easy, to one of the calculation, very complex. I think two people cooperate to complete, each has a clear division of labor, reduce the workload, but also improve the efficiency of the work, methodical.
Pair development returns the sum of the largest sub-arrays in a two-dimensional integer array