forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBricksN.html
More file actions
17 lines (17 loc) · 5.02 KB
/
Copy pathBricksN.html
File metadata and controls
17 lines (17 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html><body bgcolor="#cccccc" text="#000000"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><i>NOTE: This problem statement contains images that may not display properly if viewed outside of the applet. </i><br></br>
<br></br>
We have a set of many construction bricks. It contains exactly one base which is simply a special kind of brick of dimensions 1x1x<b>w</b>. We also have a infinite amount of bricks of <b>k</b> different kinds: 1x1x1, 1x1x2, ..., 1x1x<b>k</b>. Formally, for each <i>i</i> between 1 and <b>k</b>, inclusive, we have as many 1x1x<i>i</i> bricks as we need. For simplicity, we will call these bricks "bricks of length <i>i</i>". The following image shows the situation for <b>w</b>=9 and <b>k</b>=3: there is a base of length 9, and three brick types of lengths 1, 2, and 3.<br></br>
<br></br>
<img src="http://www.topcoder.com/contest/problem/BricksN/bricks1.png"></img><br></br><br></br>
We can stack bricks on top of other bricks (including the base) to form different structures. The design of the bricks forces us to place the bricks at integer positions only. To ensure stability, each brick other than the base must rest completely on a surface composed of other bricks or the base. The following image shows a structure that is invalid for four reasons:<br></br><br></br>
<img src="http://www.topcoder.com/contest/problem/BricksN/bricksn2.png"></img><br></br>
<br></br>
The height of a structure is the number of layers of bricks it contains. The base is not counted into the height of the structure.<br></br>
<br></br>
Two structures are different if there is a position where they differ in any way. (There are two ways in which two given structures may differ: First, there may be a position where one structure has a brick and the other does not. Second, there may be a position where both structures have bricks, but the bricks are of different types.)<br></br>
<br></br>
Given are three ints: <b>w</b>, the length of the base, <b>k</b>, the maximum length of your bricks, and <b>h</b>, the maximum height of your structure. Find the total number of different valid structures you can make. Return the total modulo 1000000007.<br></br>
<br></br>
For example, the following image shows all 83 different valid structures when <b>w</b> = 3, <b>k</b> = 3 and <b>h</b> = 2.<br></br>
<br></br>
<img src="http://www.topcoder.com/contest/problem/BricksN/bricksn83u.png"></img><br></br></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>BricksN</td></tr><tr><td>Method:</td><td>countStructures</td></tr><tr><td>Parameters:</td><td>int, int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int countStructures(int w, int h, int k)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>w</b> and <b>h</b> will each be between 1 and 50, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>k</b> will be between 1 and <b>w</b>, inclusive.</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>3</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>3</pre></td></tr></table></td></tr><tr><td><pre>Returns: 13</pre></td></tr><tr><td><table><tr><td colspan="2">The leftmost column in the picture above shows the 13 different structures of height at most 1.</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>3</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>3</pre></td></tr></table></td></tr><tr><td><pre>Returns: 83</pre></td></tr><tr><td><table><tr><td colspan="2">This is the example from the statement.</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>1</pre></td></tr><tr><td><pre>5</pre></td></tr><tr><td><pre>1</pre></td></tr></table></td></tr><tr><td><pre>Returns: 6</pre></td></tr><tr><td><table><tr><td colspan="2"></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>10</pre></td></tr><tr><td><pre>10</pre></td></tr><tr><td><pre>3</pre></td></tr></table></td></tr><tr><td><pre>Returns: 288535435</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>