July good record title

Codeforces 1063 B. Labyrinth

[] Gives a deterministic maze \ ((. 1 \ n-Leq, m \ Leq 2000) \) , to find the starting point from the respective points, can do no more than the number of left movement \ (X \) times, the number of right movement not more than (Y \) \ the number of times reached in the case of the point.

Obviously greedy to ask about the number of moving as little as possible upon arrival at each point, but two keywords difficult to maintain. In fact, when determining the starting and ending points, determining the number of moves left and right to move a certain number of times determined. When starting on the left end, to minimize the number of movements to the left; right-hand end when the starting point, still to minimize the number of movements to the left. Of course, both the right to minimize the number of movements may be. This tells us that we only need a minimum of one on it. Bfs directly into the team repeated to update maintenance.

Reflection: uncertainty. For understanding the plane distance.

Codeforces 1019 A. Elections

[] Reverse thinking there \ (n \) individual to \ (m \) a party vote ( \ (1 \ the n-Leq, m \ Leq 3000 \) ). The first \ (i \) individual to \ (p_i \) party vote, you can spend \ (c_i \) bribe to let him change his vote objects (any change). I asked how much money to spend to make at least 1 party wins.

Positive thinking hard. Consider determined can be determined to reach such a state after the last votes the party much money spent at least 1, and therefore the enumeration 1 party votes, greedy calculate the minimum cost. Complexity \ (O (^ n-2) \) . Specifically, the enumeration set to 1 vote for the party \ (k \) , then for all \ (a_i \ geq k \) , need to cut off, choose the least expensive cut. If you can not scrape together after, they chose the cheapest of people get on the line.

Reflection: Select the converse is difficult to think positive.

Codeforces 777 D. Cloud of Hashtags

[Do] are given from the back \ (n-\) string, without changing the order of the strings, allowing any extension of each string by deleting some (light can be deleted), Q total minimum deleted several character string in all lexicographic order.

Consider the relative relationship between the two strings. To make a string before than after a string dictionary small order, then go from just after the first sweep to a different place (or end) then mark just fine. I think of front to back to do so. But this will be a problem, because once lexicographical behind smaller, it will affect all previous. The correct approach is 从后往前to do so.

Reflection: In what order do you want to figure out

Codeforces 442 B. Andrey and Problem

Push formula [greedy] have \ (n \) individuals, the \ (i \) individuals \ (a_i \) probability of consent, \ (1-a_i \) probability disagree. Some people ask how to choose, so that the probability of only one person agreed maximum.

Suppose we have selected a set of \ (S \) , then the probability of \ (\ sum \ limits_ {i \ in S} [\ dfrac {a_i} {1-a_i} \ prod \ limits_ {j \ in S} ( a_j-1)] \) . Order \ (B = \ Prod \ limits_ {I \ in S} (. 1-a_i) \) , \ (S = \ SUM \ limits_ {I \ in S} \ dfrac {a_i} {. 1-a_i} \) . The probability \ (SB \) .

Now consider the addition of a \ (a_k \) , then the amount of change in thinking of an answer \ (\ Delta = (S + \ dfrac {a_k} {1-a_k}) \ cdot B \ cdot (1-a_k) -SB = B (1 -S) a_k \) . So long as \ (S <1 \) , then select \ (a_k \) answer will be larger.

Next, consider how you choose. If we consider greedy, then obviously choose the biggest \ (a_k \) will be the best, so we \ (a_k \) descending choice until sorting \ (S geq \ \ 1) So far, the complexity of the \ ( O (n-\ log n-) \) .

Why be greedy, it can be proved by contradiction.

Reflection: mathematical problems push formula is a good choice. Thinking: calculate each addition \ (\ Delta \) to obtain the total answer.

Codeforces 1096 D. Easy Problem

[DP status is defined, making thinking] gives a string, delete the first \ (i \) costs for the characters \ (a_i \) . Q. How much to spend at least the cost of making sequences not present in the original string hard(not a substring, that is, you can not continuous)

For each new character add to the mix, if not the h, a, r, done of you can not control. If you add that d, then we destroy this either directly dor destroy the front so that the front does not exist har. Want the front does not exist har, it is necessary rto do a similar thing when added. So we chose DP. Order \ (dp_ {i, j} \) representing the forward \ (I \) positions, destroy length \ (J \) prefix (may not be consecutive) minimum cost. Thus according to two earlier decisions, there \ (dp_ {I, J} = \ min \ {{I-dp_. 1,. 1-J}, {I-dp_. 1, a_i + J} \} \) . The answer is \ (\ min \ {{n-dp_, J} \} \) .

Reflection: the definition and nature of the state. This question still have to think clearly

Named on the planet Luogu P2336 meow

INDUSTRIAL title, suffix array into a range of issues, there is a differential thinking] \ (n \) individuals, each with two strings. Gives \ (m \) once asked, given a string Always ask, ask how many people in this string of two strings one appeared too. After the query output is asking everyone to the number of times.

First, the owner and ask the string and together (the middle to insert characters) do SA. Corresponding to each query suffix sorting section after section, each of the pre-extension color belongs to which each point as man, is transformed into the number of color sections, with the number of times each color is covered. The former team solved directly with Mo, who consider the difference: Every time covered, plus the remaining asking you to answer a contribution several times, each time to leave, asked to answer a few times minus the residual contribution.

Reflection: suffix array and range of issues linked to the total

Codeforces 988 D. Points and Powers of Two

Conclusion [Title] gives a number of columns, select a subset of the largest, which satisfies any two elements satisfies \ (| a_i-a_j | = 2 ^ d, (d \ geq 0) \)

Subset size can not exceed 3! Because for a subset of size three, they must be equidistant from the two ends of the otherwise not be the power of two. Therefore, with a maprecord of violence and then enumerate index to judge. Complexity \ (O (n \ log ^ 2n) \)

Reflection: using the properties of roughly determine the magnitude answers (possible values)

Codeforces 375 B. Maximum Submatrix 2

[Obtaining of a similar idea title; greedy 01] gives a matrix ( \ (. 1 \ n-Leq, m \ Leq 5000 \) sequence), the line can be arbitrarily exchanged. After the maximum possible area of the whole sub-rectangle exchange requirements.

We know that the whole of a static sub-rectangle may extend by maintaining the number of each point to the left up to 1, and then extended stack monotone most value. Then we might still maintain this thing, then this value for each column row a sequence solving.

Reflection: Since the whole sub-rectangle problem encountered is solved by maintaining the extension. Then this question should not be too far off. To go against this idea above.

Codeforces 2 B. The least round way

[Processing] gives a double value \ (n \ cdot n \) matrix, come from the top left bottom right (right or down), multiply the number of passes. How should we go so that the end result of a 0 as little as possible.

Processing the first number of each factor of the number 2 and 5 factor. Then there is an important conclusion: the minimum number of zeros at the end, the smaller the minimum value of the path 2 and a minimum path is 5. This put into question the value of double the value of a single problem.

Reflection: double value is always difficult to handle.

Codeforces 463 D. Gargari and Permutations

[FIG construction; problem given characteristic] \ (K \) of length \ (n-\) of the arrangement ( \ (. 1 \ n-Leq \ Leq 1000,1 \ Leq K \ Leq. 5 \) ), obtaining LCS.

Enumerator right. Each pair is the pre-treatment number or reverse order in each arrangement. If for all permutations of a number of sequence are the same, then this number is available as part of the LCS. Once you've identified all such numbers right, get a \ (DAG \) , you can find the longest chain.

Reflection: DP is the essence of DAG. So the key is to grasp what this DAG here yes.

Codeforces 449 B. Jzzhu and Cities

[FIG built; Shortest Path Properties] given a weighted undirected graph. Then give \ (K \) length of the bar \ (W_i \) a \ ((1, r_i) \ ) path. Asking \ (k \) paths up to several deleted, so that all point to the shortest deleted after 1 unchanged.

These \ (K \) paths in FIG added, run \ (the Dijkstra \) . While each point shortest path into a statistical degree. This is followed by \ (K \) path, if the length is greater than that corresponding to the shortest certainly omitted. If exactly equal, then the look of the shortest, greater than one could be deleted. Then the shortest path into the minus 1 degree.

Reflection: the shortest of this concept is the first encounter.

Codeforces 471 D. MUH and Cube Walls

[Review] differential matching string defined character matching change: the difference between all the characters of the two strings are the same. Asked the number of matches.

Let's analyze this match what special properties, they found that two adjacent difference is the same. So we can be pretreated an array of two differential strings, and then directly to match the array can be a difference. With KMP algorithm (O (n) \) \ can be completed.

Guess you like

Origin www.cnblogs.com/qixingzhi/p/11237074.html