National Day is Rui dynamic programming topics DAY2

National Day is Rui dynamic programming topics DAY2

Arrange - examples

  1. 1 ~ n the number of the arrangement, each of the number of two or larger than the next smaller than the next two or

    \ (f [i] [j ] \) filled before the number i, the number of unfilled are \ (J \) more than the \ (i \) a small, a peak

    \ (g [i] [j ] \) is trough

    \(f[i][j] -g[i+1][j']\)

    \(g[i][j]-f[i+1][j']\)

    You can prefix and optimization

  2. arrangement of n number of positions in exactly k satisfies \ (a_i <a_ {i + 1} \) number

    Today may be the only problem they want out of 23333

    \ (F [i] [j] \) aligned with a front number i j arranged in a small number in the number, and to consider the insertion section \ (i + 1 \) number

    Front discharge: \ (F [I] [J] -> F [I +. 1] [J] \)

    Put the middle is smaller than the number: \ (J * F [I] [J] -> F [I +. 1] [J] \)

    Put the middle number is greater than: \ ((. 1-I-J) * F [I] [J] -> F [I +. 1] [+ J. 1] \)

    Discharge rearmost: \ (F [I] [J] -> F [I] [J-. 1] \)

    Optimization can then be counted out in combination

Dp summary of arrangement process:

  1. Enumeration number / number of residual
  2. Interpolation (usually better)

Optimization of complexity

The number of states

  • Rational design
  • State is not removed by the

Metastasis

  • Prefix and
  • Data structure optimization
  • Matrix optimization (recursive)
  • trivival -> non-trivival (get rid of some of the transfer, it does not take the obvious form)

Optimization of space

  • Scroll array

Continue examples

  1. CF273D

  2. Minimizing Maximizer

    f [i] to \ (1- i \) a minimum cost are covered with the maintenance interval Fenwick tree \ (F \) minimum it

  3. CF1209E2

    I.e., such that the selected row and a maximum per

    1. Common DP: \ (m. 3 ^ n-* \)
    2. Each column need only consider the first n largest
    3. Consider each column of the same cyclic shift number of steps the answers are the same, can be optimized to \ (2 ^ nn ^ 2 \ )
  4. Peaks

    \ (n-\) the number of permutations with exactly \ (K \) number of peaks embodiment, \ (\ PMOD {239} \)

    \ (N \ leq 10 ^ {15}, k \ leq 30 \)

    \ (f [i] [j ] \) before \ (I \) number, there are \ (J \) peaks, consider adding section \ (i + 1 \) number

    1. Get rid of a preceding peak: \ (F [I +. 1] [J] + = F [I] [J] * 2J \)

    2. Ina则\ (f [i + 1] [j + 1] + = f [i] [j] * (i + 1-2 * j) \)

    Matrix multiplication can be written, and \ (M_i = M_i + 239 \ )

Suddenly, after half past four decadent (see Gangster blog), less listening to two questions

Guess you like

Origin www.cnblogs.com/lcyfrog/p/11617812.html