+ Reply to Thread
Results 1 to 2 of 2

Thread: Find max size sub matrix

  1. #1
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321

    Find max size sub matrix

    Given a binary matrix, find out the maximum size square sub-matrix with all 1
    consider the below binary matrix.
    0 1 1 0 0
    1 1 0 1 0
    0 1 1 1 0
    1 1 1 1 0
    1 1 1 1 1
    0 0 0 0 0
    Then the result should be
    1 1 1
    1 1 1
    1 1 1

  2. #2
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321
    Code:
    int n, i, j, answer = 0;
    scanf("%d", &n);
    for(i = 0; i < n; ++i) {
    	scanf("%s", &mx[i]);
    	for(j = 0; j < n; ++j)
    		if(mx[i][j] == '1')
    			size[i][j] = 1;
    }
    for(i = 1; i < n; ++i)
    	for(j = 1; j < n; ++j) {
    		if(mx[i][j] == '1')
    			size[i][j] = min(size[i][j - 1],
                                min(size[i - 1][j], size[i - 1][j - 1])) + 1;
    		if(size[i][j] > answer)
    			answer = size[i][j];
    	}
    for(i = 0; i < answer; ++i) {
    	for(j = 0; j < answer; ++j)
    		printf("1");
    	printf("\n");
    }

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find a number in a matrix
    By Surfer in forum Algorithm/Data Structure Questions
    Replies: 2
    Last Post: 21st June 2010, 14:00
  2. What will be the size of object of given class
    By Surfer in forum Bloomberg
    Replies: 0
    Last Post: 26th May 2010, 23:28
  3. Replies: 0
    Last Post: 30th May 2008, 16:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts