Adding dynamic programming version of CountPaths. This is faster than non dynamic programming version.