How many routes are there through from top left corner to top right in a 20x20 grid? Binomial Coefficent explanation

1.1k Views Asked by At

Possible Duplicate:
Counting number of moves on a grid

I'm trying to solve this computer programming problem on Project Euler: http://projecteuler.net/index.php?section=problems&id=15

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?

1

There are 1 best solutions below

1
On BEST ANSWER

HINT:

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$.