Given an N × N array of positive and negative integers, find
the sub-rectangle with
the largest sum. The sum of a rectangle is the sum of all
the elements in that rectangle.
In this problem the sub-rectangle with the largest sum is
referred to as the maximal
sub-rectangle. A sub-rectangle is any contiguous sub-array
of size 1 × 1 or greater
located within the whole array.
Input Format:
First line contains the size of matrix.
Followed by n lines and each line contain n integers
separated by space.
Output format:
Single integer which represents maximum sum of rectangle.
Sample Input:
4
0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
Sample Output:
15
Answer / guest
This problem appears to be an NP-complete problem (meaning
there is no one algorithm that will always give an optimal
answer)
You could try to take the two largest numbers and make
those the diametrically opposite vertices of the rectangle
(which works in the sample) but that method would not work
in this sample matrix:
3
1 8 -12
2 -3 9
0 -2 -4
Here that method would net you 2, whereas the optimum is 8.
The only way to solve this problem appears to be by brute
force: listing all possibilities and then choosing the best
one.
Obviously, you can use discretion with brute force--in the
sample, you can see by just looking that no rectangle using
the right half of the matrix is going to work--but you must
be careful with such eliminations as you may accidentally
eliminate the correct answer.
If there are other heuristic algorithms (such as the one
that I invented in the 2nd paragraph), I cannot find them.
| Is This Answer Correct ? | 1 Yes | 15 No |
There were N stations on a railroad. After adding X stations 46 additional tickets have to be printed. Find N and X.
Jim lies a lot. He tells the truth on only one day in a week. One day he said: "I lie on Mondays and Tuesdays." The next day he said: "Today is either Sunday, Saturday or Thursday." The next day he said: "I lie on Fridays and Wednesdays." On which day of the week does Jim tell the truth?
A husband and wife have a combined age of 91. The husband is now twice as old as his wife was when he was as old as she is now. How old is wife?
Wo kay chej hi jo saal may 1 baar aata hai months may 2 baar aata hai weeks may 4 baar aata hai or din may 6 baar
0 Answers College School Exams Tests,
What is the minimum number of numbers needed to form every number from 1 to 7,000? Example: To form 4884, you would need 2 4s & 2 8s. 4822 requires a 4, a 8, & 2 2s, but you would not count the numbers again that you had already counted from making 4884.
Can u pl send me the model question paper or previous 5 year question paper for South Indian Bank's clericl post.Pl do send it to my mailId:nan_april4@yahoo.co.in
A number of 9 digits has the following properties: ? The number comprising the leftmost two digits is divisible by 2, that comprising the leftmost three digits is divisible by 3, the leftmost four by 4, the leftmost five by 5, and so on for the nine digits of the number i.e. the number formed from the first n digits is divisible by n, 2<=n<=9. ? Each digit in the number is different i.e. no digits are repeated. ? The digit 0 does not occur in the number i.e. it is comprised only of the digits 1-9 in some order. Find the number.
10 Answers Citrix, HM Solutions, Wipro,
Ali Baba had four sons, to whom he bequeathed his 39 camels, with the proviso that the legacy be divided in the following way : The oldest son was to receive one half the property, the next a quarter, the third an eighth and the youngest one tenth. The four brothers were at a loss as how to divide the inheritance among themselves without cutting up a camel, until a stranger appeared upon the scene. Dismounting from his camel, he asked if he might help, for he knew just what to do. The brothers gratefully accepted his offer. Adding his own camel to Ali Baba's 39, he divided the 40 as per the will. The oldest son received 20, the next 10, the third 5 and the youngest 4. One camel remained : this was his, which he mounted and rode away. Scratching their heads in amazement, they started calculating. The oldest thought : is not 20 greater than the half of 39? Someone must have received less than his proper share ! But each brother discovered that he had received more than his due. How is it possible?
Six cabins numbered 1-6 consecutively, are arranged in a row and are separated by thin dividers. These cabins must be assigned to six staff members based on following facts. 1. Miss Shalaka's work requires her to speak on the phone frequently throughout the day. 2. Miss Shudha prefers cabin number 5 as 5 is her lucky number. 3. Mr. Shaan and Mr. Sharma often talk to each other during their work and prefers to have adjacent cabins. 4. Mr. Sinha, Mr. Shaan and Mr. Solanki all smoke. Miss Shudha is allergic to smoke and must have non-smokers adjacent to her. 5. Mr. Solanki needs silence during work. Can you tell the cabin numbers of each of them?
A man got 30 aples in 1 Rs.Now he want 20% of profit on it. How many apples He should Sell in 1 Rs.??
In a certain game, if 2 wixsomes are worth 3 changs, and 4 changs are worth 1 plut, then 6 plutes are worth how many wixsomes?
In a kingdom far far away, the King decided that the time has come to find a husband for his princess daughter. The King wanted to find a worthy lad for his princess, so he promised to give his daughter away to the first young (or old) man who would solve the puzzle that has stumped the best of his court mathematicians for years. The puzzle is very simple: in a palace, there are 25 rooms arranged in a square--5 rows of rooms with 5 rooms in each row. In every room there is a light switch which not only switches on/off the light in that room, but also switches the lights in the adjacent rooms--the room to the right, to the left, the room above and the room below. Initially, all of the lights are turned off. The goal is to turn the lights on in every room of the palace.