Problema
A standard die produces an integer from 1 through 6. Count all nonempty ordered sequences of outcomes whose sum is target. Different orders count separately. Return the count modulo 1,000,000,007.
Implement dice_combinations(target).
Input
target: The required sum of all rolls.
Output
Return the number of sequences modulo 1,000,000,007.
Restrições
1 ≤ target ≤ 1,000,000. Taking a count modulo 1,000,000,007 means returning its remainder after division by that number.
Exemplos
Entrada:
target = 2
Saída esperada:
expected = 2
Entrada:
long long target = 2;
Saída esperada:
long long expected = 2;
Entrada:
long target = 2;
Saída esperada:
long expected = 2;
Explicação
The two sequences are [2] and [1, 1].
Entrada:
target = 4
Saída esperada:
expected = 8
Entrada:
long long target = 4;
Saída esperada:
long long expected = 8;
Entrada:
long target = 4;
Saída esperada:
long expected = 8;
Explicação
The sequences are [4], [1,3], [3,1], [2,2], [1,1,2], [1,2,1], [2,1,1], and [1,1,1,1].
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Think of smaller sums as building blocks for the target.
Dica 2
Use a running count for each sum based on the previous six sums.
Dica 3
Be careful to apply the modulo at every addition and handle sums below 1 separately.
Complexidade esperada
O(target) time, O(target) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.