Count Sequences to K
Real-world version: Selections of Throws Scoring Exactly kThe statement here is our own: the same inputs, outputs and technique.
A run of dice throws is given as nums, each a number from 1 to 6.
A selection takes some of the throws, keeping their order, and its score is the product of the throws taken. Two selections are different when they take different positions, even if the throws taken read the same.
Return how many non-empty selections score exactly k.
Examples
Example 1
- Input
- nums = [2, 3, 4, 6, 1, 5], k = 24
- Output
- 4
Selections scoring 24 include the throws 4 and 6, the throws 2, 3 and 4, and each of those again with the throw of 1 taken as well, since taking it changes nothing about the product but does make a different selection.
Example 2
- Input
- nums = [1, 1, 1], k = 1
- Output
- 7
Any non-empty selection of throws of one scores one, and there are seven of them.
Example 3
- Input
- nums = [6], k = 5
- Output
- 0
The only selection scores 6, so nothing scores 5.
Constraints
- 1 <= nums.length <= 19
- 1 <= nums[i] <= 6
- 1 <= k <= 10^15
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_sequences(nums: list[int], k: int) -> int:public int countSequences(int[] nums, long k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Find the Number of Subsequences With Equal GCDReal-world version: Matched Gear BenchesHard
- Maximize Score After N OperationsReal-world version: Retiring Blades In Paired SessionsHard
- Climbing StairsReal-world version: Rung Ladder ClimbsEasy
- Fibonacci NumberReal-world version: Cascade Register ReadingEasy