ProgrammingVery hardCompetitive coding (CP)

How many monotone lattice paths go from the top-left corner to the bottom-right corner of a 4 by 4 grid of cells (moves only right or down)? Compute with this recursive program.

How many monotone lattice paths go from the top-left corner to the bottom-right corner of a 4 by 4 grid of cells (moves only right or down)? Compute with this recursive program.
#include <stdio.h>
int paths(int r, int c) {
    if (r > 4 || c > 4) return 0;
    if (r == 4 && c == 4) return 1;
    return paths(r + 1, c) + paths(r, c + 1);
}
int main(void) {
    printf("%d", paths(0, 0));
}
  1. A. 70
  2. B. 35
  3. C. 56
  4. D. 126

Correct answer: A. 70

The recursion counts right-down paths on a 4 by 4 grid, which equals C(8, 4) = 70. Using C(7, 3) = 35 is a common off-by-one.

More C Programming questions

Exams that ask this topic