Data Structures & AlgorithmsModerateICPC regional · DP warm-up
Problem: How many ways are there to tile a 2 x 10 board completely with 2 x 1 dominoes (placed horizontally or vertically)?
- A. 55
- B. 144
- C. 34
- D. 89
Correct answer: D. 89
Let t(n) be the tilings of 2 x n; then t(n) = t(n-1) + t(n-2) with t(1) = 1 and t(2) = 2, so t(n) = F(n+1) and t(10) = F(11) = 89.
More Coding Interview Problems questions
- Array a = [1, -1, 2, 3, -2, 4, -3, 1]. How many contiguous non-empty subarrays have sum exactly 3? Solve it with running prefix sums and a…
- For a = [3, 4, -7, 2, -2, 5, -5, 1, 6], what is the length of the longest contiguous subarray whose elements sum to 0?
- Array a = [-2, 3, -4, 6, -1, 2]. How many non-empty subarrays have a sum divisible by 5? Count prefix sums by their remainder, normalised…
- In the binary string s = "1100110100", count the non-empty substrings that contain exactly as many 0s as 1s.
- Array a = [2, 7, -3, 5, 11, 4, 9, -1, 6]. How many index pairs (i, j) with i < j have a[i] + a[j] = 10?
- Array a = [2, 1, -1, 4, -2, 3, 0, 1, 1, 0, 2]. How many indices i have the sum of the elements strictly left of i equal to the sum of the…