1. Design Ideas
(In the online search of the program code and ideas, we organize it to get the idea now) macro defines m and N, respectively, two-dimensional array of rows and columns, in the main function defines an integer two-dimensional array, the elements of the two-dimensional array is generated by the random generation function rand (), for the resulting two-dimensional array, We first calculate all the sub-arrays of the first element in the first row, and then calculate the second third to the nth, the second line to the third row until the first row, the sub-array calculated above the other two-dimensional array, and then the two-dimensional array of sub-arrays of the maximum value (according to the number of columns), Define a variable max (the number of the largest sub-arrays in a two-dimensional array), assign the value of max to 0, compare the maximum from another two-dimensional array to max, and so on, and finally get the maximum number of sub-arrays.
2. SOURCE program
#include <iostream>using namespacestd;#defineM 3#defineN 2voidMain () {intA[m][n]; intMax; ints; intcount; intB[m][m]; cout<<"the two-dimensional array is:"<<Endl; for(intI=0; i<m;i++) { for(intj=0; j<n;j++) {A[i][j]=rand ()% -- -; cout<<a[i][j]<<" "; } cout<<Endl; } for(intI=0; i<m;i++) {Count=0; for(intj=0; j<n;j++) {s=0; for(intL=0; l<n-j;l++) {s=s+a[i][j+L]; B[i][count+l]=s; } Count=count+n-J; } } //To find the maximum numbermax=b[0][0]; for(intj=0; j<m;j++) { for(intI=0; i<m;i++) {s=0; for(intR=0; r<m-i;r++) {s=s+b[r+i] [j]; if(max<s) Max=s; } }} cout<<"the maximum sub-matrices are:"<<max<<Endl;}
3. Results
4. Summary
Still can not find a good idea, find a way to solve the problem, thinking is very important, to think more, to form their own solution to the problem, two people's cooperation is conducive to better understanding of the program and ideas, really hope that in the future with their own way, their ideas to solve the problem.
5. Work Photos
Mengxiangjuan: Mainly responsible for code review and Code test plan;
Chen Jie: mainly responsible for program analysis, code programming.
Classroom Exercise 3