GATE Computer ScienceHardGATE CS (PYQ pattern)
A 6 × 6 grid is given row by row, where # is a blocked cell: row1 "....#.", row2 "..#...", row3 ".#..#.", row4 "....#.", row5 "#.....", row6 "...#..". From the top-left to the bottom-right cell, each move goes one cell right, one cell down, or one cell diagonally down-right (a diagonal move is allowed even if the two cells beside it are blocked). How many distinct paths avoid all blocked cells?
- A. 9
- B. 141
- C. 170
- D. 157
Correct answer: D. 157
DP: P[r][c] = P[r−1][c] + P[r][c−1] + P[r−1][c−1] for open cells and 0 for blocked ones, with P[1][1] = 1. Filling the table row by row gives 157 at the bottom-right. With only right/down moves the count is just 9, so forgetting the diagonal term is the main trap.
More Algorithms questions
- Twelve meetings occupy CLOSED time intervals [1,5], [2,6], [5,9], [6,7], [4,8], [7,11], [8,12], [3,10], [9,13], [10,14], [12,15], [13,16]…
- The length of the longest bitonic subsequence (strictly increasing and then strictly decreasing; either part may be empty-length-1) of [4…
- Four greedy rules are proposed for choosing the maximum number of mutually non-overlapping activities: I. repeatedly choose the activity…
- Which of the following statements about the 0/1 knapsack problem is/are correct? I. The O(nW) dynamic programme is polynomial in n and in…
- Six tasks have (processing time, deadline): (3,6), (2,8), (4,9), (1,5), (5,15), (2,10). They run one after another on a single machine…
- In how many ways can 12 be written as an ordered sum of parts from {1, 2, 3} such that no two adjacent parts are equal (e.g. 1+2+1+3+… is…