Lattice Paths
Starting at the top-left corner of a 20 x 20 grid, how many routes exist to the bottom-right corner if only rightward and downward moves are permitted? Formally: count the number of monotone lattic...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Starting in the top left corner of a \(2 \times 2\) grid, and only being able to move to the right and down, there are exactly \(6\) routes to the bottom right corner.

How many such routes are there through a \(20 \times 20\) grid?
Problem 15: Lattice Paths
Mathematical Development
Definitions
Definition 1. A monotone lattice path from to is a sequence of unit steps, each either or , such that exactly steps are and exactly steps are .
Definition 2. Let denote the number of monotone lattice paths from to .
Theorems
Theorem 1 (Closed-form path count). The number of monotone lattice paths from to is
Proof. A path is a binary string of length over the alphabet containing exactly copies of . The path is uniquely determined by specifying the positions of the right-steps among the total steps. The number of ways to choose these positions is .
Theorem 2 (Pascal recurrence). The function satisfies:
Proof. Boundary conditions: There is exactly one path from to (all -steps) and one path to (all -steps).
Recurrence: Every path to with takes its last step from either (a right-step) or (a down-step). These two sets of paths are disjoint and exhaustive, so .
Lemma 1 (Equivalence with Pascal’s triangle). for all .
Proof. By strong induction on . The base case gives . For boundary cases, and . For , by the inductive hypothesis and Theorem 2:
where the last equality is Pascal’s identity: .
Theorem 3 (Exact evaluation via telescoping product). The binomial coefficient can be computed as
Moreover, the partial products are integers for all .
Proof. We have
For integrality of partial products: , which is an integer since it counts the number of -element subsets of an -element set.
Corollary 1. The multiplicative formula computes using only integer arithmetic (no fractions), since each intermediate quotient is exact.
Proof. At step , the running product equals … more directly: after multiplying by and dividing by , the result equals , which is an integer by Theorem 3.
Numerical Evaluation
Editorial
We compute the central binomial coefficient multiplicatively instead of expanding full factorials. The loop traverses and multiplies the accumulator by at each step, which stays integral by the binomial-coefficient derivation. This is sufficient because the resulting product is exactly , the number of lattice paths.
Correctness. By Theorem 3, this computes . By Corollary 1, all divisions are exact.
Pseudocode
Algorithm: Central Binomial Coefficient by Multiplicative Update
Require: An integer n ≥ 0.
Ensure: The number of lattice paths through an n x n grid.
1: Initialize P ← 1.
2: For each k in {1, 2, ..., n} do:
3: Update P ← P · (n + k) / k.
4: Return P.
Complexity Analysis
Proposition. The multiplicative formula runs in time and auxiliary space (assuming -cost arithmetic on integers of size bits).
Proof. The loop executes iterations, each performing one multiplication and one division. The result has bits by Stirling’s approximation:
If arbitrary-precision arithmetic is used, each multiplication costs bit operations, giving total. With machine-word arithmetic (valid for since ), the cost is .
Remark. The dynamic programming approach (Theorem 2) requires time and space (using row-by-row computation).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
// Compute C(40, 20) via the telescoping product (Theorem 3).
// Each intermediate result * (20+k) / k is exact (Corollary 1).
long long result = 1;
for (int k = 1; k <= 20; k++)
result = result * (20 + k) / k;
cout << result << endl;
return 0;
}
"""Project Euler Problem 15: Lattice Paths"""
def solve():
from math import comb
return comb(40, 20)
answer = solve()
assert answer == 137846528820
print(answer)