Data Structures & AlgorithmsHardCodeforces Div2 C
Grid rows (top to bottom): '....', '.#..', '...#', '#...', '....'. '#' is an obstacle, '.' is free. Starting at the top-left cell, you move only right or down, and you may not enter obstacles. How many paths reach the bottom-right cell?
- A. 35
- B. 0
- C. 14
- D. 7
Correct answer: D. 7
The count is dp[r][c] = dp[r-1][c] + dp[r][c-1] for free cells, and dp = 0 on obstacles. Ignoring the obstacles or forgetting the 'right only' restriction changes the number, and doubling is the usual mistake of counting mirror routes.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A triangle of numbers has rows [9], [7, 6], [9, 7, 4], [6, 1, 5, 3], [6, 9, 2, 4, 5]. Starting at the top, each step goes to one of the…
- How many non-empty contiguous subarrays of [-4, 2, -7, 5, -1, 3, -2, 6] have a sum divisible by 3 (the sum 0 counts as divisible)?
- A Java program stores dp[i] in an int array, sets dp[0] = dp[1] = 1, uses dp[i] = dp[i-1] + dp[i-2] for i up to 50, and never applies a…
- Words available: a, ab, b, ba, aa, abba, bab, aab. How many different ways can the string 'abbaaab' be split into a sequence of these…
- A rod of length 8 can be cut into integer pieces. A piece of length i sells for price[i], where price = [0, 1, 5, 8, 9, 10, 17, 17, 20]…
- In how many ways can 12 be written as a sum of DISTINCT positive integers, where order does not matter (so 12 itself counts as one way)?