Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Counting number of moves on a grid

I'm trying to solve this computer programming problem on Project Euler:

Starting in the top left corner of a $2\times2$ grid, there are 6 routes (without backtracking) to the bottom right corner.

How many routes are there through a $20\times20$ grid?

I've seen a solution using nCr, where n = 40 and r = 20.

Could someone explain to me how this work, please?

share|cite|improve this question

marked as duplicate by Arturo Magidin, leonbloy, mixedmath, Hans Lundmark, amWhy Jul 27 '11 at 2:52

This question was marked as an exact duplicate of an existing question.

up vote 0 down vote accepted


Consider the general problem of the number of paths in a rectangular grid $m\times n$. Call $P(m,n)$ this number.

You should be able to figure out a formula for $P(m,n)$ observing that $P(1,n)=P(m,1)=1$ and $P(m,n)=P(m-1,n)+P(m,n-1)$ when both $m$ and $n$ are $>1$.

share|cite|improve this answer
The same hint in different language: Tilt the rectangles/squares 45 degrees, so that the (1,1) position is at the top. Do you see Pascal's triangle forming? – Jyrki Lahtonen Jul 26 '11 at 18:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.