Two-dimensional connectivity and maximum values

Source: Internet
Author: User

Title: Returns the and of the largest interconnected subarray in a two-dimensional integer array

Idea: The two-dimensional array of each row as a one-dimensional array, in an array of the largest sub-array of connectivity, all find out after determining whether these groups of small connected arrays are connected, add the connected together. Finally, in determining whether there is a positive number in the maximum connectivity range of the previous one-dimensional array, add.

Code:

#include <iostream>using namespace Std;void main () {int m,n,i,j,smark,mmark,t2;int sum;int up[100],down[100],t[ 100];int a[100][100],b[100];cout<< "Enter rows and columns of two-dimensional arrays"; Cin>>m>>n;for (i=0;i<m;i++) {for (j=0;j<n;j + +) {cin>>a[i][j];}} for (i=0;i<m;i++) {for (j=0;j<n;j++) {b[j]=a[i][j];} int C[100]={0};int sum1=0,max1=0,k;for (k=0;k<n;k++) {if (sum1<0) {sum1=b[k];} ELSE{SUM1=SUM1+B[K];} C[K]=SUM1;} Max1=c[0];for (k=0;k<n;k++) {if (Max1<c[k]) {max1= c[k];mmark = k;}} for (k = mmark;k >= 0;k--) {if (c[k] = = B[k]) {smark = K;break;}} Sum=max1;      Up[i]=smark;                                   Down[i]=mmark;t[i]=sum;} T2=t[0];for (i=0;i+1<m;i++) {if (up[i]<=down[i+1] && down[i]>=up[i+1]) {t2+=t[i+1];} for (j=up[i];j<up[i+1];j++) {if (a[i+1][j]>0) t2+=a[i+1][j];                   Discriminant independent positive}}cout<<t2<<endl;}

 

Summary: The task of the difficulty coefficient significantly improved, in the design of the idea is also thought of several options but the degree of implementation is not high, and finally through the discussion with the roommate to make today's program in the execution of any problem, now the problem is still in the efforts to solve, through the programming of the understanding of the group more deeply, This task in my thinking in the design process to give themselves a greater harvest, in response to this problem design ideas when the failure of design new Silk Road process to improve their ability.

Two-dimensional connectivity and maximum values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.