Tap here to switch tabs
Problem
Submissions

Problem: Count Routes to Climb a Rectangular Grid

Try to solve the Count Routes to Climb a Rectangular Grid problem.

Statement

You are given an n×mn \times m grid of characters grid and an integer d. The grid consists of empty cells '.' and obstacle cells '#'.

A climbing route is a sequence of distinct cells (r1,c1),(r2,c2),…,(rk,ck)(r_1, c_1), (r_2, c_2), \dots, (r_k, c_k) satisfying the following conditions:

  • The route starts at any empty cell in the bottom row, where r1=n−1r_1 = n - 1 and grid[r1][c1]=[r_1][c_1] = '.'.

  • The route ends at any empty cell in the top row, where rk=0r_k = 0 and grid[rk][ck]=[r_k][c_k] = '.'.

  • Every visited cell along the route is empty, meaning grid[rt][ct]=[r_t][c_t] = '.' for all 1≤t≤k1 \leq t \leq k.

  • The row index is nonincreasing at every step, meaning rt+1≤rtr_{t+1} \leq r_t for all 1≤t<k1 \leq t < k.

  • The Euclidean distance between any two consecutive cells along the route is at most d, meaning (rt+1−rt)2+(ct+1−ct)2≤d\sqrt{(r_{t+1} - r_t)^2 + (c_{t+1} - c_t)^2} \leq d for all 1≤t<k1 \leq t < k.

Return the total number of valid climbing routes.

Constraints:

  • 1≤n==1 \leq n == grid.length ≤750\leq 750

  • 1≤m==1 \leq m == grid[i].length ≤750\leq 750

  • grid[i][j] is '.' or '#'.

  • 1≤d≤7501 \leq d \leq 750

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Routes to Climb a Rectangular Grid

Try to solve the Count Routes to Climb a Rectangular Grid problem.

Statement

You are given an n×mn \times m grid of characters grid and an integer d. The grid consists of empty cells '.' and obstacle cells '#'.

A climbing route is a sequence of distinct cells (r1,c1),(r2,c2),…,(rk,ck)(r_1, c_1), (r_2, c_2), \dots, (r_k, c_k) satisfying the following conditions:

  • The route starts at any empty cell in the bottom row, where r1=n−1r_1 = n - 1 and grid[r1][c1]=[r_1][c_1] = '.'.

  • The route ends at any empty cell in the top row, where rk=0r_k = 0 and grid[rk][ck]=[r_k][c_k] = '.'.

  • Every visited cell along the route is empty, meaning grid[rt][ct]=[r_t][c_t] = '.' for all 1≤t≤k1 \leq t \leq k.

  • The row index is nonincreasing at every step, meaning rt+1≤rtr_{t+1} \leq r_t for all 1≤t<k1 \leq t < k.

  • The Euclidean distance between any two consecutive cells along the route is at most d, meaning (rt+1−rt)2+(ct+1−ct)2≤d\sqrt{(r_{t+1} - r_t)^2 + (c_{t+1} - c_t)^2} \leq d for all 1≤t<k1 \leq t < k.

Return the total number of valid climbing routes.

Constraints:

  • 1≤n==1 \leq n == grid.length ≤750\leq 750

  • 1≤m==1 \leq m == grid[i].length ≤750\leq 750

  • grid[i][j] is '.' or '#'.

  • 1≤d≤7501 \leq d \leq 750