Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C
A frog starts at position 0 and wants to reach position 12 on a number line. Each move it jumps forward by 1, 3 or 4 units. In how many different ordered sequences of jumps can it reach exactly 12?
- A. 927
- B. 60
- C. 169
- D. 84
Correct answer: C. 169
Let ways[x] be the number of jump sequences that land on x, so ways[x] = ways[x−1] + ways[x−3] + ways[x−4]. The sequences differ by order, so this counts every path rather than the number of distinct sets of jumps.
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
- Grid values [[9, 9, 4], [6, 6, 8], [2, 1, 1]]. A path moves to one of the four neighbouring cells (up, down, left or right) each step, and…
- A square matrix is [[2, 1, 3], [6, 5, 4], [7, 8, 9]]. A falling path starts in row 0 and goes down one row per step, moving to the cell…
- A stick of length 9 must be cut at the positions [5, 1, 7, 3]. A cut costs the current length of the stick piece it splits, and the cuts…
- How many binary strings over the alphabet {a, b} of length 6 contain EXACTLY 2 occurrences of the adjacent pair "ab" (occurrences may not…
- How many binary strings of length 9 contain NO occurrence of the substring 010?
- In how many ways can the integer 10 be written as a sum of AT MOST 3 positive integers, where order does not matter (for example 10 = 7 +…