Dynamic Programming - Print all paths from (0,0) to (n,n) in Grid/Lattice
You can solve this problem using a recursive formulation of print all paths from a point $(i,j)$ to the target $(n,n)$ in the grid. I call this function $f(i,j)$. So the all paths will be in $f(0,0)$ call.

$f(i,j) = \begin{cases}
\emptyset &amp; if\ \ {i&gt;j}\\
\emptyset &amp; if\ \ \neg( {0\leq i\leq n\ \wedge 0\leq j\leq n) }\\
\{(n,n)\} &amp; if \ \ i = n \wedge j = n\\
\bigcup_{p\,\in\, f(i+1,j)\,\cup\,f(i,j+1) } \ \ \{(i,j)\}\cup p &amp; \text{otherwise}
\end{cases}$

By example, two of all paths from $f(0,0)$ when $n=4$ are:

blue path = {{0, 0}, {0, 1}, {1, 1}, {1, 2}, {2, 2}, {2, 3}, {3, 3}, {3, 4}, {4, 
  4}}

red path = {{0, 0}, {0, 1}, {0, 2}, {1, 2}, {1, 3}, {2, 3}, {2, 4}, {3, 4}, {4, 
  4}}



So, although programming is not in the scope of this site, I think is good to see a implementation for a memoization version of the above algorithm.
asdf

from functools import wraps

def memo(func):
    cache = {}

    @wraps(func)
    def wrap(*args):
        if args not in cache:
            cache[args] = func(*args)
        return cache[args]
    return wrap

@memo
def f(i, j):
    global n
    if i &gt; j:
        return []
    if not (0 &lt;= i &lt;= n and 0 &lt;= j &lt;= n):
        return []
    if i == n and j == n:
        return [[(n,n)]]
    alls = []
    for path in f(i, j+1)+f(i+1, j):
        if len(path) &gt; 0:
            alls += [[(i,j)] + path] 
    return alls

n = 4
for path in f(0,0):
    print path