Recursion, c++

Правка en1, от IF-THEN, 2019-09-10 02:43:18
bool dfs(int r, int c) {
    if (r > n || c > m || vis[ndx(r, c)] || grid[ndx(r,c)] == '#') return false;
    if (r == n && c == m) return true;
    if (r!=1 || c!=1) vis[ndx(r, c)] = true;
    return dfs(r+1, c) || dfs(r, c+1);
}

Why Does the previous code terminate once a call is evaluated as true ?

In other words, Why it doesn't mark each reachable cell that does not have "#", as expected ?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский IF-THEN 2019-09-10 02:43:18 442 Initial revision (published)