Lane Direction Signs
Time limit2sMemory limit1024 MB
Count the assignments of nonempty subsets of m directions to n lanes such that allowed directions are nondecreasing across lanes and every direction appears in some lane.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
When organizing traffic at complex intersections, restrictions are placed on the maneuvers drivers may make depending on the lane they used to approach the intersection, so that the paths of drivers performing different maneuvers do not cross. A <> sign is used for this; the figure on the right shows an example of such a sign installed before one of the intersections in Saint Petersburg.
Consider a road leading to an intersection where roads meet. A driver approaching the intersection along this road can potentially continue in different directions: back along the road they came from, or along one of the remaining roads. Number the possible directions from 1 to from left to right from the approaching driver's point of view. Number 1 is a U-turn back along the road the driver used to approach the intersection, number 2 is a turn onto the leftmost road, and so on.
Suppose the road has lanes. Number the lanes from 1 to from left to right, so the leftmost lane is number 1, the next is number 2, and so on. A <> sign permits each lane to travel in some of the possible directions. The following conditions must hold:
- if travel in direction is permitted from lane , and travel in direction is permitted from lane , with , then ;
- travel in at least one direction is permitted from each lane;
- travel from at least one lane is permitted in each direction.
The traffic safety inspection service is interested in how many different <> signs can be installed before such an intersection. Help them find the answer.
Input
The input file contains two integers: and (, ).
Output
Output a single number: the number of possible <> signs that can be installed before the intersection.
Hint
In the example, the following <> signs are possible: