Crew Shi Li Haisu
First, the topic
Outputs the largest sub-array in a two-dimensional ring array and
Second, the design idea
Combining the method of solving one-dimensional annular array and ordinary two-dimensional array, the street is a method to solve the two-dimensional annular array.
Third, the source code
#include <iostream.h>#include<time.h>#include<stdlib.h>intQiumax (intArry[],intmax) { inti; Longsum; for(i=0;i<5; i++) { for(i=0;i<5; i++) {Arry[i+5]=Arry[i]; } } for(intj=0;j<5; j + +) {sum=0; for(intk=j;k<5+j;k++) {sum=sum+Arry[k]; if(sum>max) {Max=sum; } } } returnMax;}intMain () {intQiumax (intarry[Ten],intmax); inti,j,k; intarry[5][Ten]={{1,1,1,-1,-1},{1,1,1,-1,-1},{1,1,1,-1,-1},{1,1,1,-1,-1},{1,1,1,-1,-1}}; intarry1[Ten]={0,0,0,0,0,0,0,0,0,0}; intmax=arry[0][0]; for(i=0;i<5; i++) { for(j=0;j<5; j + +) {arry[i][j+5]=Arry[i][j]; } } for(i=0;i<5; i++) { for(j=i;j<5; j + +) { for(k=0;k<5; k++) {Arry1[k]+=Arry[j][k]; } Max=Qiumax (Arry1,max); } for(k=0;k<Ten; k++) {Arry1[k]=0; }} cout<<"MAX is"<<" "<<max<<Endl; return 0;}
Iv. Results
Five, experimental experience
This experiment is not very difficult, just to combine the first two ideas, modify the next two programs can be.
But in the invocation of the function of the argument is that we have a problem, corrected after the transfer of a deeper understanding of the parameters.
Outputs the largest sub-array in a two-dimensional ring array and