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 | 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 | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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 |
---|