First, the title: Returns the number of the largest subarray in a two-dimensional integer array.
Second, requirements:
(1) Enter a two-dimensional shaping array with positive numbers in the array and negative values.
(2) The two-dimensional array is connected to the end of the line, like a first and last tape.
(3) One or more consecutive integers in the array make up a sub-array, each of which has a and.
(4) The maximum value of the and of all sub-arrays is evaluated.
Third, the problem-solving ideas:
The two same arrays are merged into an array, and the method of finding the maximal subarray of two-dimensional array is solved
Iv. Source code:
#include <iostream>using namespacestd; #include"math.h"voidMain () {intn=5; intm=5; intn=-Ten; intm=Ten; inta[5][Ten]; intb[Ten]; intA=0; intmax=0; intmax=0; cout<<"Please enter an array element:"; for(intI=0; i<n;i++) { for(intj=0; j<m;j++) {cin>>A[i][j]; A[i][m+j]=A[i][j]; } } for(intI=0; i<n;i++) { intH=i; for(ints=0;s<2*m;s++) {B[s]=0; } Do { intE=0; intC=0; intD=0; for(intk=0;k<2*m-1; k++) {B[k]=b[k]+A[h][k]; } A=b[0]; Max=b[0]; for(intj=1;j<2*m-1; j + +) { if(a<0) {A=B[j]; if(max<A) {Max=A; E=J; C=J; D=e; } Else{e=J; } } Else { if((j-d) = =M) { Break; } if(b[j]<0) { if(max<A) {Max=A; C=j-1; D=e; } A=a+B[j]; } Else{A=a+B[j]; if(max<A) {Max=A; C=J; D=e; } } } } if(h==0) {MAX=Max; } Else if(max<Max) {MAX=Max; } h++; } while((h<N)); } cout<<"Maximum number of word groups and for:"<<MAX; }
V. Summary of tasks:
Each time through a tense and interesting programming, see a new program came into being, inevitably excited, through this programming, need to integrate the original knowledge to summarize, one can, oneself also need more efforts to better realize the program's compilation.
Returns the sum of the largest sub-arrays in a two-dimensional integer array