Recent public ancestor (LCA) Problems
LCA (t, u, v): In the root tree T, ask a node X that is the farthest from the root so that X is the ancestor of node u and v at the same time.
The LCA problem can be solved using a simple DFS method,
View code
1 # Include Stdio. h > 2 # Include String . H > 3 # Define Maxcompute 32200 4 Int C [Max], level [Max]; 5 Int N; 6 Int Get_val () 7 { 8 Int RET ( 0 ); 9 Char C; 10 While (C =
Everyone else said it was a bare minimum charge stream. After thinking for a long time, I couldn't think of how to do it. I finally understood it after reading other people's problem-solving reports.
The key lies in the composition and conversion.
The title of hangdian is also in reverse order. Its scale is much smaller than that of poj, so it does not need to be merged and direct brute force statistics are required.
This requires the smallest number of reverse orders. At the beginning,
During the graph creation process, the above line of letters corresponds to the following line one by one and uses km to find an optimal match.
# Include # include # include # include # include using namespace STD; # define min (a, B) a
As soon as I woke up, it was already four o'clock, so I decided to pick a question.
View code
# Include # Include String . H># Include Char STR [ 5000 ]; Int Main (){ Int I, J, K; While (Gets (STR )){ Char S [] =" 0000 " ; Int Len = strlen
// The equation for this question is not listed, I can understand it only after reading the problem-solving report. // set DP [I] [J] to the largest subsequence ending with a [J] And/dp [I] [J] = max (DP [I] [J-1] + A [J], DP [I-1] [k] + A [J]) //
Vertex connectivity: Removes at least a few vertices to make the graph not connected.
Suppose two neighboring vertices u and v;
Two paths from u to V without common internal vertices are called independent tracks. The maximum number of
The difficulties of this question are illustrated.
The method for creating a graph is as follows: if you can run to the cave within a given s time (to determine the distance between two points), then the two points are connected, otherwise they
# Include # include #include #include using namespace STD; const int max = 10010; vector edge [Max]; int st [Max]; int dfn [Max], low [Max]; int top, btype, tdfn; // btype: number of connected blocks int belong [Max]; // The connected bool INS
At the beginning, I aimed at this question. I didn't understand the question. I wanted to read other questions. I didn't expect that there would be more than a dozen people. I decided to continue reading it, I found that it would be nice to
The diagram is as follows:
Use the row number as the X set vertex, And the col row number as the y set vertex. Based on the coordinate X given by the question, y connects the X and Y sets vertices with edges, and calculates the least vertex
I learned the dictionary tree tonight and got a familiar topic. I directly set the template. At the beginning, I ran over Sicily. However, when poj times out and crashes, I read other people's problem-solving reports, open a 10000 array directly to
Convert to the minimum vertex overwrite count
The chart is as follows: X sets X blocks x, then the two vertices are connected by edges. Then, the number of least vertex overwrites (maximum matching) is obtained, that is, the answer.
Pay
Suppose a rectangle with the coordinates (x1, Y1) in the upper left corner and (X2, Y2) in the lower right corner. Now we use a two-dimensional tree array to sum the ranges (X2, Y2) represents 0, 0 --, X2, Y2 large rectangle sum, sum (x1-1, Y2)
Suffix Arrays are a powerful tool for processing strings. Suffix Arrays can solve most suffix trees. Because they are easier to implement than suffix trees, they are favored by ACM fans, of course there are still some problems that can only be
LCA is used to solve the problem of recent public ancestor, Tarjan's Algorithm Is an offline algorithm. The time complexity is O (n + q). N indicates the data size, and Q indicates the number of queries.Use and query the set. The key is that the
I have been calling this question for a long time, and finally I have overcome it.
Graph Theory, templates must be highly reliable
Abstract question:
Two tasks to be completed
1: at least a few vertices can be traversed to traverse all
The template is used directly, but the templates of Zhejiang Provincial university of Zhejiang Province seem to be not very useful... Write it by yourself.
Note that the question is about the length of the three sides. First, convert the three sides
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service