Problem 15. Lattice paths

Description

public class euler15 {
    public static void main(String[]args) {
       	int N = 21;
        long[][] m = new long[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
             	if ((i == N-1 || j == N-1) && j != i)
              	    m[i][j] = 1;
              	else
                    m[i][j] = 0;
            }
       	}
       	for (int j = N-2; j >= 0; j--) {
            for (int i = N-2; i >= 0; i--) {
               	m[i][j] = m[i+1][j] + m[i][j+1];
            }
        }
        System.out.println(m[0][0]);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>