PROBLEM STATEMENT
Manao has a board filled with digits represented as vector board. The j-th character of
the i-th element of board represents the digit written in cell in row i, column j of the board.
The rows are numbered from top to bottom and the columns are numbered from left to right.
Manao is going to cut it into several non-overlapping fragments. Each of the fragments will be a
horizontal or vertical strip containing 1 or more elements. A strip of length N can be interpreted
as an N-digit number in base 10 by concatenating the digits on the strip in order. The horizontal
strips are read from left to right and the vertical strips are read from top to bottom. The
picture below shows a possible cutting of a 4x4 board:
The sum of the numbers on the fragments in this picture is 493 + 7160 + 23 + 58 + 9 + 45 + 91 =
7879.
Manao wants to cut the board in such a way that the sum of the numbers on the resulting fragments
is the maximum possible. Compute and return this sum.
DEFINITION
Class:CutTheNumbers
Method:maximumSum
Parameters:vector
Returns:int
Method signature:int maximumSum(vector board)
NOTES
-The numbers on the cut strips are allowed to have leading zeros. See example #2 for details.
CONSTRAINTS
-board will contain between 1 and 4 elements, inclusive.
-board[0] will be between 1 and 4 characters long, inclusive.
-Each element of board will be of the same length as board[0].
-Each character in board will be a decimal digit ('0'-'9').
EXAMPLES
0)
{"123",
"312"}
Returns: 435
Manao can cut out both rows in whole, obtaining 123 + 312 = 435. He also could cut the columns one
by one for a total of 66, or cut the first column and the residual rows one by one, obtaining 13 +
23 + 12 = 48, or even cut out single elements, but would not get a better sum.
1)
{"99",
"11"}
Returns: 182
It's better to cut out the whole columns.
2)
{"001",
"010",
"111",
"100"}
Returns: 1131
The numbers on the strips may have leading zeros. Cutting the columns in whole, Manao obtains 0011
+ 0110 + 1010 = 1131.
3)
{"8"}
Returns: 8
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.