Can someone tell me how to calculate the coefficient of x^k in the term: (1+x+x^2......x^n1)(1+x+x^2+....x^n2)........(1+x+x^2.....n^m)
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
vlyubin
|
13 years ago,
#
|
+5
Basically what you want to find is the number of ways to express k as a sum of m non-negative numbers (with some restrictions because of n1,n2...). The simple way to solve this is using DP. However, I am almost sure that one can come up with an analytic formula.
For dp, dp[i][j] - the coefficient of x^j in the term: (1+x+x^2......x^n1)(1+x+x^2+....x^n2)........(1+x+x^2.....x^ni) . Then dp[i][j] = (SUM t = 0 to min(ni,j)) dp[i-1][j-t]. Comment : we move from left to right with "using" more and more brackets.At dp[i][j] - we "inlude" bracket i. dp[1][j] = 1 for all 0<=j<=n1 ; = 0 for n1<j<= k. For analytic solution: for k from 0 to minimal of n1...nm (denote min) we can find the coefficient by using binomial expansion formula. After that if we want min+1, the result is binomial expansion - "the impossible ways". We can find latter as follows. Suppose n1<n2<...; min = n1. Then "impossible ways"=the coefficient before x^0 (its 1) in product of all brackets except the first (since there is no x^n1+1 to make the total product be x^n1+1). But you need to explore cases where n1=n2 and so on. Up to you) As for DP you can notice that we don't really need the full table but only dp[i-1][...] to find dp[i][...]. So we need only two linear arrays, which saves a lot of space. I think if you don't know the exact formula and there is problem like that on the contest - there is no reason to find it, just use the easier solution (if its OK in terms of time and space complexity). And I'm really sorry if my DP formula is wrong, but I hope you can guess what the approach is now.
→
Reply
|
phantom11
|
13 years ago,
#
^
|
←
Rev. 2
→
0
Did you mean this in your dynamic approach:: for(j=0;j<=a[0];j++) dp[0][j]=1; p=a[0]; for(k=1;k
→
Reply
|
phantom11
|
13 years ago,
#
^
|
0
Did you mean this in your dynamic approach::
where a[] contains the upper limit of each term;m=no. of terms. for(j=0;j<=a[0];j++) dp[0][j]=1; p=a[0]; for(k=1;k<m;k++) { p+=a[k]; for(j=0;j<=p;j++) { sum=0; for(z=0;z<=Math.min(j,a[k]);z++) sum+=dp[k-1][j-z]; dp[k][j]=sum; } }
→
Reply
|
Name |
---|