Pair Development member: Zhu Shaohui, Hou Tao Bright
Zhu Shaohui: Responsible for program analysis, code programming
Hou Tao: Responsible for code review and Code testing
Design ideas:
According to the largest subarray of the one-dimensional subarray and the example, the two-dimensional array into a number of one-dimensional sub-arrays, such as M-row N-column array can be divided into (m+1) *M/2 Sub-array, in the order of each one-dimensional array of the largest sub-array, and put these and into an array, The maximum value of this array is the same as the maximum subarray of the two-dimensional array. The time complexity of this algorithm is O (n^3).
Code:
#include <iostream>using namespacestd;voidMain () {intm,n,i,j,a[ -][ -]; cout<<"Please enter the size of the Matrix (m*n):"; CIN>>m>>N; cout<<"Please enter a matrix:"<<Endl; for(i=0; i<m;i++) { for(j=0; j<n;j++) {cin>>A[i][j]; } } intsum,max=a[0][0],s[ -],k=0; for(i=0; i<m;i++) { while(k+i<m) { for(j=0; j<n;j++) {S[j]=s[j]+a[k+i] [j]; } Sum=0; for(j=0; j<n;j++) { if(s[j]+sum>S[j]) {Sum=s[j]+sum; } Else{sum=S[j]; } if(sum>max) {Max=sum; }} k++; } k=0; for(j=0; j<n;j++) {S[j]=0; }} cout<<"the maximum value of the sub-matrix is"<<max<<Endl;}
:
Summarize:
This programming I mainly responsible for the program analysis, code programming, which has greatly improved my programming ability. One-dimensional arrays and two-dimensional arrays to find the maximum number of sub-arrays and the idea is similar, visible programs can be categorized. Through the cooperation we completed the programming and testing, felt the importance of cooperation and division of Labor, but also learned how to communicate when there are differences, to persuade each other, the harvest is great.
To find the largest subarray of two-dimensional arrays