"10.19" does not drop the longest sequence (DP) · complete knapsack problem (spfa optimization DP) · recent common ancestor (+ DFS tree line order)

I was abused ...

A. longest sequence does not fall


Examination room playing the wrong solution, successfully transferred two and a half hours or not A,

In fact ideas and positive solutions very close, but did not think directly before and after a $ D $ $ D $ proposed direct

Indeed some time thinking disorder, but when playing the first two and the last two cycles festival raised,

Since the question in the range of $ D $ is small, so the longest common subsequence of at most $ D $ different numbers

So we can expect the same number of middle period must be a period of a few can be moved into the middle, essentially the same

B. complete knapsack problem


I did not expect is to map the topic ah

Considering the great range of $ W $, $ V $ however small range, so we began to transform the original definition of the DP $ $ equation

$ F_ {i, j, k} $ elected to represent the first two items $ I $ $ L at this time is greater than the selected items have $ $ $ J a, and the minimum value of $ S $, in this case $ S% vmin = k $

The smallest value of $ v $ vmin $ $ express that appears, in fact, are the same .....

Finally, we only need to determine and compare the answers $ f [n] [j] [W% vmin] $ whether $ <= W $ can be, the same as the modulo plus several $ $ V

You will be able to take $ W $, consider the transfer, $ v_ {i}> L $ is not to say

Worth considering if $ v_ {i} <time = L $, we find $ f [i] [j] [s] = min (f [i-1] [j] [s], f [i] [ j] [sv [i]% vmin] + v [i]) $ transferred from

$ $ Transfer time of the DP is in the same state,

In order to ensure proper transfer of the line, very magical uses $ spfa $

We coupled weights $ $ f_ {i-1, j, s} $ with a super source node and each of $ s, and then connect the $ s $ twenty-two The transition equation

In this way we ensure that the transfer is complete backpack that is the nature of the items can be infinitely selected, and the transfer is to ensure that each point has passed a by a super source

The attached edges.

C. Recent Common Ancestor


Consider black spots will only continue to increase,

So every emergence of a black point to consider his contribution is to modify the sub-tree, so the DFS order to maintain sub-trees on it

Guess you like

Origin www.cnblogs.com/Wwb123/p/11708938.html