Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Number of paths in matrix
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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); }
cl.exe
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1.02 sec, absolute running time: 0.05 sec, absolute service time: 1.08 sec
edit mode
|
history
|
discussion
56 56