Two common models

Two common models

bzoj4321

Numbered from 1 to n people arranged in a row, and asked how many rows of difference method so that any adjacent two of the number of 1 or -1 is not.
n <= 1000

Gap destruction: two adjacent

We set \ (F [i] [j] \) of 1 to i are arranged, there is a difference between adjacent groups j, i and i-1 and the number of programs are not adjacent;

We set \ (G [i] [j] \) of 1 to i are arranged, there is a difference between the adjacent group j, and i and i-number of adjacent Scheme 1;

Consider the insertion position i + 1, are:

Does not destroy the non-adjacent gaps of i, and i, and does not destroy adjacent space, and does not damage adjacent the slot i, and destruction gap (g transfers occur only) four kinds adjacent to i.

Respectively push the number of programs:

Consider first the program number i and i-1 adjacent to:

Consider i-2, i-1 and i relationship of:

  1. i-1 and i-2 adjacent, then we will be in the middle i i-1 and i-2 is: will this i-1, i-2 adjacent pair apart, but added i and i-1 pair, so the number of adjacent corresponds to no increase nor decrease, i.e. \ (g [i] [j ] \) there is one from \ (g [i-1] [j] \ ) transferred from the (i-1 before the number, i-1 and i-2 adjacent, adjacent consensus j)
  2. i-1 and i-2 adjacent to, but not in the middle i and i-1 to i-2, i-1 and on the other side: we will not destroy i-1 and i-2 on the adjacent, and the new addition of i-1 and i of the pairs of adjacent, thus increasing the number of adjacent 1, after the transfer is j, then the first transfer should be 1-J: \ (G [i-1] [J -1]\)
  3. i-1 and i-2 nonadjacent: then we can also i i-1 on the side, which increases a pair of adjacent, since i can be placed around both sides of the i-1 were two cases, Therefore: \ (F [i-1] [-J. 1] * 2 \) because i-1 and i-2 are not adjacent to say, it is by F;

\(g[i][j]=g[i-1][j]+g[i-1][j-1]+f[i-1][j-1]*2\)

The same can be deduced \ (f [i] [j ] \) of the transfer equation:

  1. Originally i-1 and i-2 adjacent, j i is inserted adjacent to any pair of numbers, so that the destruction of a pair, so that the program from \ (g [i-1] [j + 1] \ ) , with a (j + 1-1) species may be selected from a position (i-1 and i-2 pair can not be removed, because the insert will form new).
  2. Originally i-1 and i-2 are not adjacent, the adjacent i j insert any pair number, so that the destruction of a pair, so that the program from \ (f [i-1] [j + 1] \) , with a (j + 1) can be selected from the kind of position.
  3. It may not open adjacent number i, can be derived from \ (G [i-1] [J] \) * (. 1-ij of) (i-1 can be inserted and i-2, does not change the number of ) or \ (F [. 1-I] [J] \) * (ij of-2)

\(f[i][j]=g[i-1][j+1]*j+f[i-1][j+1]*(j+1)+g[i-1][j]*(i-j-1)+f[i-1][j]*(i-j-2)\)

The final answer is \ (f [n] [0 ] \)

Time complexity of O (n ^ 2).

BZOJ2560 string of beads

N-beads, between the i and j have beads \ (C [i] [j] \) different pieces of rope optional. Between each pair of beads may choose not to connect the rope, may be connected to select one of a rope.
Q. How many kinds of programs can become a connected graph of n beads.
n <= 16

FIG communication routines count: subtracting the total number of programs is not connected, the program number without communication, can enumerate a communication point set of points where the number of blocks (the size of some of the issues is), the communication program with the set of points multiplied by the remaining points can be set on the total number of programs. ? ? ?

We set two arrays, G [s] represents a case where all the s-state, i.e., the point in the state s edge between any two arbitrary even (even without including side case), F [s] is represented by the state s legitimate , the points of all the legitimate communication state even if the obtained s. The answer is f [2 ^ n-1].

\(g[s]=g[s-(1<<i)]+\sum_{j\in s-(i<<i)}[i][j]\) \(O(n*2^n)\)

Then we can easily find g [s], we find g [s], to consider how to seek f [s], f [s ] is g [s] minus all the illegal situation. Then we can enumerate all subsets of s, set subset i, then the situation is not lawful G [i] f * [s ^ i] , we subtract these circumstances, be able to find f [s] a .

Guess you like

Origin www.cnblogs.com/zhuier-xquan/p/11330013.html