CodeForces 1204E "Natasha, Sasha and the Prefix Sums" (dynamic programming or a combination of mathematics - number of application Cattleya)

 

Portal

 

• the meaning of problems

  由 n One  and  one  -1 consisting of $ C_ {n + m} ^ {n} $ sequence;

  Prefix and the largest sum of all sequences;

  And provides for maximum and minimum prefix is 0;

•answer

  Defined $ (i, j) $ represented by a sequence of i-1, j -1, a one;

  $ (I, j) $ Total $ C_ {i + j} ^ {i} $ different combinations;

  $ (I-1, j) $ Total $ C_ {i + j-1} ^ {i-1} $ different combinations;

  $ (I, j-1) $ Total $ C_ {i + j-1} ^ {i} $ different combinations;

  If both the $ (i-1, j) $ a $ C_ {i + j-1} ^ {i-1} $ and $ (i, j-1) $ The $ C_ {i + j-1} ^ {i} $ beginning or end of possible combinations of 1 or -1 are inserted;

  That is $ (i, j) $ the number of kinds of different combinations, i.e. $ C_ {i + j} ^ {i} = C_ {i + j-1} ^ {i-1} + C_ {i + j-1} ^ {i} $;

 

  The range of n, m's ($ \ leq 2000 $), consider the use of DP This question is resolved;

  First, define $ dp [i] [j] $ result represented by $ (i, j) $ consisting of $ C_ {i + j} ^ {i} $ sequence, all sequences and summing the maximum prefix ;

  Pre-knowledge of the above, it is easy to think of $ (i, j) $ by $ (i-1, j) $ and $ (i, j-1) $ obtained;

  That is to say, $ dp [i] [j] $ by $ dp [i-1] [j] $ and $ dp [i] [j-1] $ transferred from;

  Because the $ (i, j) $ by $ (i-1, j) $ and $ (i, j-1) $ inserted at the beginning of the end or get 1 or -1, that in the end is inserted into the insert at the beginning or the end of it?

  Because the meaning of the questions is seeking to make maximum prefix sum, therefore, we consider the insertion of 1 or -1 at the beginning;

    • At the beginning of $ (i-1, j) $ 1 is inserted, which means that $ C_ {i + j-1} ^ {i-1} $ sequences are prefixed maximum increased by 1, then
      • $dp[i][j] += dp[i-1][j]+C_{i+j-1}^{i-1}$
    • At the beginning of $ (i, j-1) $ insertion -1, which means that $ C_ {i + j-1} ^ {i} $ prefix sequence reduces the maximum value of 1, then
      • $dp[i][j] += dp[i][j-1]-C_{i+j-1}^{i}+h[i][j-1]$

Guess you like

Origin www.cnblogs.com/violet-acmer/p/11718617.html