Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2014 /round2 /ski_resort_planning.html
wjomlex's picture
2014 Problems
718fd53 verified
raw
history blame
3.2 kB
<p>
Charlotte is a very successful Olympic skier. All the sponsor deals she landed during her career has made her very rich, so she has decided to retire from skiing. Charlotte has just bought an entire mountain, and is planning to build a ski resort there. The mountain has <strong>N</strong> interesting points, numbered 0, 1, ..., <strong>N</strong>-1. Point 0 is the top of the mountain. Point <strong>i</strong> is further down the mountain than point <strong>j</strong> if <strong>i</strong> &gt; <strong>j</strong>.
</p>
<p>
For each point <strong>a</strong> &gt; 0, she has decided on a different point <strong>b</strong>, which has the following property: All paths from the top of the mountain to point <strong>a</strong> have to go through point <strong>b</strong>, and there is no point <strong>c</strong>, such that <strong>b</strong> &lt; <strong>c</strong> &lt; <strong>a</strong> and all paths from the top of the mountain to point <strong>a</strong> go through point <strong>c</strong>. A path can never go up the mountain.
</p>
<p>
You have been given the task to plan where the slopes go. You can add slopes directly between any two different interesting points. How many ways can you lay out the slopes for her resort, while satisfying the conditions above?
</p>
<p>
Two ways of laying out the slopes, <strong>X</strong> and <strong>Y</strong>, are different if there exists two interesting points <strong>a</strong> and <strong>b</strong>, such that the slope between <strong>a</strong> and <strong>b</strong> exists in <strong>X</strong> or <strong>Y</strong>, but not in the other.
</p>
<p>
You can assume that the skiers will be able to get to a lift from any point, so you don't have to worry about getting them all the way down for every path. You have to be able to reach all interesting points from the top.
</p>
<h3>Input</h3>
<p>
The first line of the input consists of a single integer <strong>T</strong>, the number of test
cases. <br />
Each test case starts with a line containing the integer <strong>N</strong>. <br />
The next line of each test case contains <strong>N</strong>-1 integers, <strong>A<sub>1</sub></strong>, <strong>A<sub>2</sub></strong>, ..., <strong>A<sub>N-1</sub></strong>, where <strong>A<sub>i</sub></strong> is the lowest interesting point that all paths to point <strong>i</strong> has to pass through.
</p>
<h3>Output</h3>
<p>
For each test case <strong>i</strong> numbered from 1 to <strong>T</strong>, output "Case #<strong>i</strong>: ", followed by the number of ways you can lay out the slopes given the constraints in the input, modulo 1,000,000,007
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong> T </strong> &le; 20 <br />
2 &le; <strong>N</strong> &le; 5000 <br />
<strong>A<sub>i</sub></strong> &lt; <strong>i</strong> for each of <strong>A<sub>1</sub></strong>, <strong>A<sub>2</sub></strong>, ..., <strong>A<sub>N-1</sub></strong><br />
</p>
<h3>Examples</h3>
<p>
The first example has to have the following slopes:
<pre>
0 -&gt; 1
0 -&gt; 2
1 -&gt; 3
</pre>
In addition, we can choose whether or not to add the slope
<pre>
1 -&gt; 2
</pre>
The total will be 2; one for adding the slope and one for not adding it.
</p>