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 ?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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 ?
Name |
---|
What do you mean by getting? Is it appending or sum?
it's sum
Even though X is really big, it doesn't really matter because N can be maximum 100, and every element can be maximum 100; therefore, maximum sum can be 10000. Can't we just do a simple dp?
an element can be used as many time as you want
So if A = {2,1}, X = 4, so ways are : {2, 2} {2,1,1} {1,1,1,1} etc..
Ok, I see.
An element can be used as many as you want, so maximum sum isn't 10^4. You can't do a simple dp here.
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)).