** Things **:
There are several ways to arrange n k-faces in a column so that the numbers on the face are S?
** Question type **:
Dynamic Planning
** Solutions **:
DP [I] [J] There are several methods to save the sum of the first I partitions as J.
Transition equation: DP [I] [J] = DP [I-1] [J-1] + dp [I-1] [J-2] +... + dp [I-1] [J-K];
There are N * s of statuses, And the transfer complexity is K. The simple practice will definitely time out. How can we optimize it?
Imagine the DP array as a two-dimensional matrix of the plane, and then the transfer equation, we can find that the transfer equations of DP [I] [J] and DP [I] [J-1] overlap a lot, as shown below:
DP [I] [J] = DP [I-1] [J-1] + dp [I-1] [J-2] +... + dp [I-1] [J-K];
DP [I] [J-1] = DP [I-1] [J-2] +... + dp [I-1] [J-K] + dp [I-1] [j-K-1];
Therefore, we can obtain DP [I] [J] = DP [I] [J-1]-DP [I-1] [j-K-1] + dp [I-1] [J-1];
The transfer has been optimized to O (1) complexity, but the DP array is N * s = W complexity. Therefore, we need to optimize the array to O (s ).
Although this question is classified as DP, there are no special restrictions, so there can be more efficient methods, and the O (n) complexity can be achieved by the principle of rejection.
If f (I) = n operators, at least I have more than K operators, and the total number of workers is S;
Then the answer is F (0)-f (1) + F (2)-f (3)... ± F (n)
F (I) method: N operators select I with C (n, I) types (this I is guaranteed to exceed K, other super does not matter ), in each case, the s-I * K should be divided into N parts and each part should be at least 1. So f (I) = C (n, I) * C (s-I * K-1, N-1 );