Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя I_love_PMK

Автор I_love_PMK, 10 лет назад, По-английски

Given an array A has N integer (1 <= a[i] <= 100, N <= 100) and a number X (X <= 10^9)

Counting number of ways that can get X from a subsequences of A (an element can be used as many as you want)

anyone has a idea for it ?

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What do you mean by getting? Is it appending or sum?

»
10 лет назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится

Looks pretty straight-forward. Let dx be the answer for x. If you know dx, dx + 1, ..., dx + 99, then , so it is a linear combination of dx, dx + 1, ..., dx + 99. Which means that transition from dx, dx + 1, ..., dx + 99 to dx + 1, ..., dx + 100 can be done by matrix multiplication, and the whole problem can be solved by taking a power of this matrix (with complexity max(a[i])^3 * log(X)).