-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCutTheNumbers.html
12 lines (12 loc) · 4.64 KB
/
CutTheNumbers.html
1
2
3
4
5
6
7
8
9
10
11
12
<html><head><title>CutTheNumbers</title></head><body ><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>Manao has a board filled with digits represented as String[] <b>board</b>. The j-th character of the i-th element of <b>board</b> 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.
<br></br><br></br>
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:
<br></br><img src="http://www.topcoder.com/contest/problem/CutTheNumbers/CutTheNumbers_1.jpg"></img><br></br>
The sum of the numbers on the fragments in this picture is 493 + 7160 + 23 + 58 + 9 + 45 + 91 = 7879.
<br></br><br></br>
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.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>CutTheNumbers</td></tr><tr><td>Method:</td><td>maximumSum</td></tr><tr><td>Parameters:</td><td>String[]</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int maximumSum(String[] board)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td colspan="2"><h3>Limits</h3></td></tr><tr><td>    </td><td><table><tr><td>Time limit (s):</td><td>2.000</td></tr><tr><td>Memory limit (MB):</td><td>64</td></tr></table></td></tr><tr><td colspan="2"><h3>Notes</h3></td></tr><tr><td align="center" valign="top">-</td><td>The numbers on the cut strips are allowed to have leading zeros. See example #2 for details.</td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>board</b> will contain between 1 and 4 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>board[0]</b> will be between 1 and 4 characters long, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>board</b> will be of the same length as <b>board[0]</b>.</td></tr><tr><td align="center" valign="top">-</td><td>Each character in <b>board</b> will be a decimal digit ('0'-'9').</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"123",
"312"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 435</pre></td></tr><tr><td><table><tr><td colspan="2">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.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"99",
"11"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 182</pre></td></tr><tr><td><table><tr><td colspan="2">It's better to cut out the whole columns.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"001",
"010",
"111",
"100"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1131</pre></td></tr><tr><td><table><tr><td colspan="2">The numbers on the strips may have leading zeros. Cutting the columns in whole, Manao obtains 0011 + 0110 + 1010 = 1131.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"8"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 8</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr></table><p>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)2003, TopCoder, Inc. All rights reserved. </p></body></html>