48 analog solution to a problem

A. String Master

$ O (n ^ 3) $ casually do.

 

 

 

B. Tourist Attractions

Because the data range of $ n ^ 2 $ without any problems.

Consider setting $ DP (i, j, k) represents $ node i to the node j, and k walk step number of the program.

Obviously $ dp (i, j, 1) = du (i) -1 $, but to return to j, other solutions are possible.

Link provided $ (i, j) represents the 0/1 variable is $ i, j Unicom.

$ Dp (i, j, 2) = \ sum \ limits_ {k, link (i, k)} dp (k, i) -link (k, j) $, j when k may back time, may cause repeat count, it subtracts.

$dp(i,3)=\sum \limits_{k,link(i,k)}dp(k,i)$

$ans=\sum \limits_{i=1}^{n}dp(i,3)$

How to get the bottleneck $ dp (i, j, 2) $, violence seeking $ O (n ^ 3) $ a.

The formulas may wish to add and subtract the two apart, then come to find bitset maintain what i j k again come to the number of programs on it.

 

 

 

C. Walk

70 points violence, each value only when bfs first time, again to update all of its subsets.

Complexity enumerated subsets is $ O (3 ^ k) $ a. (K val for the next largest binary digits)

The question is how the $ 3 ^ k $ edges into a $ 2 ^ k $ level.

Consider reducing the number of each of the weights to a weight value of 1 for the right side edge built 0, then the number of side is $ k * 2 ^ k $ level.

Weights to the point value 0 is built side edge weight, the edge weight value corresponding to a point of building the right.

Since only 0/1 the weight of two forms, deque bfs.

 

Further, if the point value to the weight of the right side edge of a building, the edge weight value 0 to the right of point construction.

Bfs such conduct is wrong, because the points are updated may lead to more answers in advance.

Guess you like

Origin www.cnblogs.com/skyh/p/11566239.html