I_love_PMK's blog

By I_love_PMK, 12 years ago, In English

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 ?

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
12 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
12 years ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

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)).