AdvancedAlgorithms.DiagonalShorcuts.CountPaths C# (CSharp) Method

CountPaths() private static method

Counts the paths from 0,0 to x,y on a grid Allows diagonal paths
private static CountPaths ( int x, int y ) : System.Int64
x int
y int
return System.Int64
        private static Int64 CountPaths(int x, int y)
        {
            //table to store dynamic programming subproblem reults
            Int64[][] table = new Int64[x + 1][];

            //initialize edges to be 1;
            for (int i = 0; i <= x; i++)
            {
                table[i] = new Int64[y + 1];
                table[i][0] = 1;
            }
            for (int j = 0; j <= y; j++)
                table[0][j] = 1;

            //calculate each position bottom up
            for (int i = 1; i <= x; i++)
            {
                for (int j = 1; j <= y; j++)
                {
                    //the value for 1 square is the value of the ones before it added together
                    table[i][j] = table[i - 1][j] + table[i][j - 1] + table[i - 1][j - 1];
                }
            }

            return table[x][y];
        }
DiagonalShorcuts