42 provincial election simulation

A. coin

  First, you can guess the contribution of each bill are independent, so long as the contribution calculated for each bill finally merged on the line.

  Done directly complexity will die.

  For consideration of each bill, the number of sheets with the contribution of the differential array apparently monotonous, so you can use the dynamic heap to maintain the current optimal solution.

  Found that only use a maximum of $ n $ states, so the dynamic calculation of these states, all without having to pre-out.

B. B

  My approach is to seek out the original tree has at least the same number of programs k edges, inclusion and exclusion you can get just the right number of programs.

  Number scheme may be required by the tree DP, set $ f [i] [j] [k] $ $ I $ denotes the subtree selected edges of $ J $, $ I $ communication where the block size is $ k $ the number of programs.

  Then the number of trees in order to come out of that equation can count program.

  Then this thing can continue to optimize. Consider the actual meaning of that expression, in fact, a selected number of programs Unicom point in each block. You can then continue to optimize the third dimension becomes $ 0 / $ 1, China Unicom represents the current block is already elected.

  Such complexity is $ O (n ^ 2) $ a.

  Then the approach is a solution to a problem routine, the arguments is the matrix Gaussian elimination + tree, substituting several values ​​can be directly engaged. I have done many times before.

C. battery

  For each point can be found to limit the form of a number of points simultaneously selected without restriction, do not seem, however, can be found, if there are two turrets can be simultaneously in the same direction through this point, then you must hit two forts a.

  So after a fort at most two points, and from different directions, otherwise no solution, then it becomes a restriction can not not vote for two things.

  So is a simple 2-sat model, set directly on the line.

Guess you like

Origin www.cnblogs.com/hzoi-cbx/p/12458927.html