Start at the point
on the cartesian plane. At any point, one can move either up one unit, or right one unit. The ultimate destination is the point
.
Calculate the number of unique paths there are from the origin to the destination, and answer it modulo . But, before you do, there's a little catch:
Points of the form are off limits for all even , with the implicit exceptions of . Paths that touch any of these points may not be counted towards your total.
Details:
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
We'll set P = 1 0 9 + 7 for brevity.
Let f ( d ) be the number of different paths from any point ( x , y ) to another point ( x + d , y + d ) , ignoring the forbidden points for now. Since the total number of moves that need to be made is 2 d , and exactly d of them need to be rightward moves, we have:
f ( d ) = ( d 2 d )
It's important to note that we can compute f ( d ) in limited space modulo P - something which Wolfram will automagically do for you, but that you'll have to implement yourself if using a lesser calculator. This can be accomplished via three observations:
( k n ) mod P ≡ k ! ⋅ ( n − k ) ! n ! mod P ≡ n ! ⋅ ( k ! ⋅ ( n − k ) ! ) − 1 mod P
x − 1 mod P ≡ x P − 2 m o d P Euler's Theorem
a b mod P can be computed in O ( lo g 2 b ) steps, using exponentiation by squaring
These three things let us compute f ( d ) mod P relatively quickly.
Now, we need to account for the forbidden points. We can do this through a simple application of the inclusion-exclusion principle .
More succinctly, let's define g ( n ) to be the number of ways to get from ( 0 , 0 ) to ( 2 n ⋅ 1 0 5 , 2 n ⋅ 1 0 5 ) , without hitting any forbidden points in between (we ignore the fact that the destination might be a forbidden point for this calculation), and let h ( n ) be the same as g ( n ) , except ignoring the forbidden point restriction entirety. Considering all unique-to-order ways there are to sum to 5 , the inclusion-exclusion principle gives us:
h ( n ) = f ( 2 ⋅ 1 0 5 ⋅ n )
g ( 5 ) = h ( 5 ) − 2 h ( 4 ) h ( 1 ) − 2 h ( 3 ) h ( 2 ) + 3 h ( 3 ) h 2 ( 1 ) + 3 h 2 ( 2 ) h ( 1 ) − 4 h ( 2 ) h 3 ( 1 ) + h 5 ( 1 )
We can use a calculator to get h ( n ) mod P for all necessary n . Then, we can plug into the above formula, and arrive at the answer:
g ( 5 ) ≡ 5 3 0 0 2 3 4 0 7 mod P
The inspiration for this problem can be found here . It is quite a bit more difficult than this one, and requires some strong programming skills to solve!