damn 544

Meaning of the questions:

There are two sequences of length n, two numbers are not repeated sequences. The number of the first number of a sequence can be of any sort, find how many sequences are arranged such that a first position corresponding to the second sequence number is greater than the ratio of the number corresponding to the position of the second sequence is less than a multi-m.

solution:

The first than the second plurality m, assuming that the first x has a large, there is the following formula:

\(x-(n-x)=m => 2*x=n+m\)

If \ ((n + m) \ ) is an odd number, the answer is 0, is even, then there is a large calculation \ ((n + m) / 2 \) number of permutations for th

It is provided two arrays \ (U, V \) , the first two sorting sequence. Order \ ([i] h \) represents the ratio of the second sequence (u [i] \) \ digits small.

Order \ (dp [i] [j ] [k] \) represents the first sequence before the \ (I \) digits have \ (J \) th not assigned, allocated with a \ (K \) th a large number of species than the second sequence.

Transfer equation:

\(dp[i+1][j-x+1][k] += dp[i][j][k]*A(h[i+1]-h[i],x)*C(j,x)\)

\(dp[i+1][j-x]k+1] += dp[i][j][k]*A(h[i+1]-h[i],x)C(j,x)(h[i+1]-i+j-x)\)

Where \ (x \) digits for this assignment. \ (= 0 <X <= min (J, H [I +. 1] -H [I]) \) .

trick: the surface complexity of the algorithm is \ (O (n-^. 4) \) , however, the final layer of cycle \ (\ sum_1 ^ n (h [i + 1] -h [i]) = n \ ) , so the actual complexity \ (O (n-^. 3) \) .

Guess you like

Origin www.cnblogs.com/gooooooo/p/12290485.html