Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Number of paths in matrix
//Title of this code #include <iostream> const int n = 4; const int m = 6; int matrixPaths2(int n, int m) { if (n == 1 || m == 1) return 1; return matrixPaths2(n, m - 1) + matrixPaths2(n - 1, m); } // With saved matrix values int t[n][m]; int matrixPaths(int n, int m) { if (n == 1 || m == 1) return 1; if (t[n - 1][m - 1] == -1) t[n - 1][m - 1] = matrixPaths(n, m - 1) + matrixPaths(n - 1, m); return t[n - 1][m - 1]; } int main() { for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) t[i][j] = -1; std::cout << matrixPaths(n, m); std::cout << std::endl; std::cout << matrixPaths2(n, m); }
run
|
edit
|
history
|
help
0
ria
dynamic_cast in assert Causing Error
Program of cube
hangman
Zero
Wide string to lowercase
Regex success
Static cast of Enum
hangman
Preserving strict aliasing Union example