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 | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 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)).