Problem Statement
A hiker has set out to conquer a hill. The Trail Guide for the hill lists information known about the hill. The It lists how tall the "hill is" and how far it's to the other side of the The hill. Next, it gives a list of landmarks that would be encountered while hiking the hill. The only things is that are known about this landmarks are their height, and the order in which they appear the trail. Finally, on this hill, there are three types of terrain:
Type 1:rising terrain. In this type of terrain, the elevation of the "Hill rises one meter vertically for every meter so is traveled horizontall Y.
Type 2:level terrain. In this type of terrain, the elevation of the hill remains constant.
Type 3:falling terrain. This terrain ' s elevation falls one meter vertically for every meter of that is traveled horizontally.
All three types of terrain can last for only multiples of one horizontal meter.
You are given an int maxheight (the maximum height of the hill, assuming the hill starts and ends at height 0), an int Distance (how far horizontally one must travel "over" top and "hike on" the other bottom), and a side] Landmarks, which contains the heights of the landmarks on the trail. The order of the "elements in Landmarks" is the order in which they'll be encountered on the trail. All landmarks must is at least one horizontal meter apart.
Given all of this information, your must return how many different valid paths is hiker that could. A path on the "hill is a sequence consisting" of the three types of terrain for the entire distance of the "hill". Two paths are different if and only if in least one horizontal meter, the terrain type of one path is not the same as The terrain type of another path. A path is valid if and only if the path:1. Starts in height 0 and ends at height 0 2. Has no other locations with height 0, or height below 0 (otherwise it would to two hills, or a valley) 3. Has at least one point where the the "the" is equal to MaxHeight (otherwise, the hill would be smaller) 4. Does not go above maxheight (otherwise, it would is taller) 5. Is laid out such that the landmarks could being placed in the "order given" at points on the trail. Note This two landmarks cannot appear at the same point on the trail, and even if they are at the same height. They must is at least 1 meter apart
If No valid paths exist, return 0.
Definition
Class:
Hillhike
Method:
Numpaths
Parameters:
int, int, int[]
Returns:
Long
Method Signature:
Long numpaths (int distance, int maxheight, int[] landmarks)
(Be sure your the IS public)
Limits
Time limit (s):
2.000
Memory Limit (MB):
64
Notes
The C + + bit data type is long long
Constraints
Distance would be between 2 and inclusive.
MaxHeight would be between 1 and inclusive.
Landmarks would contain between 0 and elements, inclusive.
Each element of landmarks would be between 1 and maxheight, inclusive.
The return value is less than or equal to 2^63-1 (it'll fit into a long)
Examples
0)
5
2
{}
Returns:3
1)
2
45
{}
returns:0
2)
5
2
{2,2}
Returns:1
The only path which could contain both landmarks is:
_
/ \
/ \
distance:12345
3)
8
3
{2,2,3,1}
Returns:7
4)
38
11
{4,5,8,5,6}
returns:201667830444