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 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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 ?
Название |
---|
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)).