Atcoder disorderly doing

Source: Internet
Author: User

Recently, I feel like I have a rigid mind, nothing will do ...

ARC103 F Distance sums test instructions

Given the distance and \ (d_i\) of I\ points to all points, it is required to construct a valid tree. The distance that satisfies the first \ (i\) point to all other points and is \ (d_i\) .

\ (n \le 10^5\) .

Skills

Looking for a special amount to roll out the whole tree form

Exercises

In the whole tree, there are two kinds of special points. One is the center of gravity, which is the distance and the smallest point, the other is the leaf node, which is the distance and maximum node. Consider if we first determine the center of gravity, then it is not very good to push down, because we do not know the size of the subtree. Consider pushing up from the leaf node, recording the size of the current subtree so that I can directly get the distance from the Father node. Since the topic guaranteed the distance and the difference of all points, I can determine the father of this point directly. Note after pushing up to the root node, you also need to check the distance of the root node and whether it is correct. Because we do this only guarantees the distance of the adjacent nodes and the correctness of the difference.

ARC101 E ribbons on tree test instructions

Given a tree \ (n (n \equiv 0 \bmod 2) \) nodes, you need to divide this \ (n\) node into the \ (\frac{n}{2}\) Group, two nodes per group. This \ (\frac{n}{2}\) Group of Point pairs form a \ (\frac{n}{2}\) path. How many different grouping schemes are available so that each edge of the tree is overwritten by at least one of the paths.

\ (n \le 5000\) .

Skills

Simplify the restriction with the principle of the tolerant repulsion.

Exercises

Direct DP can only do the complexity of \ (O (n^3) \) . The direct DP is probably the dp_{i,j}\ ( i\) Point of the child tree, the number of the children to the father's side is covered by the \ (j\) side of the scheme. Because of the number of links that must be enumerated when merging, the complexity will come to \ (O (n^3) \) .

Consider the allowance, then the tree can be regarded as broken into a number of unicom blocks, unicom block random pairing. This way if you do \ (n\) the DP, it is still \ (O (n^3) \) , because you need to do the \ (n\) DP, each time the DP still needs to remember a current subtree size.

Consider doing \ (n\) The DP has some waste, can you melt the allowance into DP inside? The answer is yes. You only need to take the transfer factor on the previous \ ( -1\) when you choose to break off an edge.

ARC 101 F Robots and exits test instructions

The axis has \ (n\) a robot and \ (m\) export. Each time you can pair \ (n\) the coordinates of a robot at the same time \ (+1\) or \ ( -1\) . When there is an exit on the robot's position, the robot disappears from the exit. How many different kinds of robots are going out of the export program number. The two scenarios are different when and only if a robot disappears from a different outlet.

\ (n \le 10^5\) .

Skills

Ingenious Modeling and transformation topics

Exercises

First of all, each robot will only disappear from his left and right two exits. Consider abstracting each robot as a point on a two-dimensional plane, where the horizontal axis of the robot represents the distance from the left exit, and the ordinate indicates the distance from the right exit of the robot. Then a scheme can be abstracted from \ (( 0,0) \) to \ ((\infty,\infty) \) a contour line. The robot in the upper left corner of the contour line disappears from the left exit, otherwise it disappears from the right exit. So we just need to count the number of footprints.

Consider how contour lines are counted and do not remember the weight. Set \ (dp_i\) indicates the number of contour lines that pass through the i\ point. Then the legal transfer point is the first (i\) point in the upper-right corner of all points, indicating that the contour line first up a paragraph, and then to the right for the remainder of the paragraph. The DP can be optimized with a tree-like array. Time complexity \ (O (n \log N) \).

ARC100 F Colorful Sequences test instructions

Given a string with a length of \ (m\) and a character set size of \ (k\) . All occurrences of the number of strings in a string that meet the following conditions are evaluated.

  1. The length of the string is \ (n\), and the character set size is \ (k\).
  2. This string contains at least one substring that satisfies this substring as a \ (1\) to \ (k\) arrangement.

\ (M \le n \le 25000,k \le 400\).

Skills

Consider the contribution of the parent string to the answer.

Exercises

The number of occurrences of a string in a thread can be very difficult to do if the thread is used. Consider the contribution of the parent string to the answer, if we determine where the parent string appears at the end. Then put aside the second limit, the position on both sides of the parent string can be filled.

Consider what to do after adding the second limit. If the parent string contains two identical characters, the \ (1\) to \ (k\) arrangement must not cross the parent string. So this arrangement is bound to appear on both sides of the parent string. As long as the length of the very long non-repeating sequence departing from the left and right sides is calculated, it is possible to go to the left and go to a separate DP. DP is probably the memory \ (dp_{i,j}\) that currently takes into account the i\ character, from the first \ ( i-j + 1\) locations to the first \ (i\) locations are different, and the first \ (i\) Number of scenarios with the same location as the \ (i-j\) location. The DP exploits the prefix and can do the complexity of \ (O (NK) \) .

If the characters contained in the string are different, each character is equivalent. Consider converting the desired into a string that satisfies the condition, containing the sum of the number of substrings that have a length of \ (m\) and the different characters of the \ (m\) character, and finally only need to divide the answer by one \ (\binom{k}{m}m!\) . The process of calculation can be solved with a DP similar to the first case. More than one dimension is required to indicate whether it is legal, and two arrays to indicate the sum of occurrences.

Note that if this string contains a \ (1\) to \ (k\) arrangement, a special sentence is required.

Code length \ (\texttt{3.4kb}\) DP question ...

ARC099 F Eating Symbols Hard Test instructions

Given a string of length \ (n\) , this string consists of,,, + - > < four characters. Find out how many substrings of this string have the same weights as the original string.

The weight of a string is defined as the operation that executes the string in order. The action moves the pointer to the + location \ (+1\) , and the action - positions the pointer at \ ( -1\) , moving the >,< pointer right or left, respectively. At the beginning of the pointer at \ (0\) , the weights of the two strings are the same when and only if each bit is the same as the array generated by the operation.

\ (n \le 250000\).

The very rare will do the F-question ...

Exercises

Note that the array after the concatenation of the two strings can be merged directly (O (1) \) , so the Hash can be used to solve the problem. So the idea is relatively simple. You only need to insert each prefix into the hash table, and then remove a prefix of equal length for each prefix, and then match the parent string. Removing the prefix can be translated into a prefix to the parent string. So just add a prefix to the parent string and look it up in the hash table.

ARC098 F Donation Test Instructions

Given a graph of \ (n\) points,\ (m\) edges. Each point of this graph has two weights \ (a_i,b_i\). You will pick a point from this chart as the starting point and then start traversing the graph. You can reach a node \ (i\) when and only if your hand has at least \ (a_i\) dollars. When you arrive at a node \ (i\) , you can choose to donate \ (b_i\) to this point. You need to donate to each point once. How many dollars do you have at least?

\ (n,m \le 10^5\) .

Skills

It's too divine ... I don't know where the trick is.

Exercises

There are two properties that can be noted first

    1. You will definitely donate to this point at the last passing point.
    2. Define \ (\max (a_i-b_i,0) \) for the weight of this point, then the greater the weight of the point will try to put in front of the donation.

The first is obviously because you have less money in your hand after the donation. So if we put the donation through that point for the last time, the plan will not be worse; Consider if we guarantee the first nature, we will get a way to donate: first identify a point, in turn, donate this point of the sub-link block, leaving a sub-unicom block, then donate this point, and finally donated the remaining sub-unicom block.

The precondition of the second nature is the first one. That is, to satisfy the first limit, and then try to satisfy the second nature. Assuming that the point weights that we determine are not the largest, then consider exchanging the points with the most weighted points, it must not be worse. To visualize the understanding is that if we put the weight of the points in front, will give the latter point left a certain space, more than the weight of the flower will be less. If you want to have a formal understanding, you can see the DP in the equation to understand.

Given these two properties, let's take a little bit of thought. Each time from the global selection of one of the most weighted points, the point will be broken down to form a number of unicom blocks. Next we need to find out which Unicom block is the best. Finding the best unicom block can be solved using DP. You can get a tree by always handing it down. DP should be simpler here, set \ (dp_i\) indicates that the sub-tree of the (i\) Point needs to spend the least amount of money. Then there will be

\[dp_x = \min\{a_x,\max (dp_y,a_x-sum_y) \}\]

where \ (a_x\) represents the weight of \ (x\) ,\ (sum_x\) represents the sum of the \ (b\) values of the \ ( x\) subtree. Last \ (Dp_{rt} + sum_{rt}\) is the final answer. DP does not need to build the tree, directly with a check set maintenance can be.

ARC097 F Monochrome Cat test instructions

Given a tree of \ (n\) points, each node in the tree will have two colors, black and white. There is a cat walking in the tree, it can choose the starting point freely. It can perform the following two actions on this tree.

  1. Flips the color of the node it is in, which takes a cost of \ (1s\) .
  2. Go to a node that is adjacent to its current position and flip the color of the new node, which takes a cost of \ (1s\) .

Ask at least how much time it takes to turn this tree into full black.

\ (n \le 10^5\) .

Skills

Link a path to a loop to consider superfluous contributions

Exercises

This problem is basically a self-fix it ...

First, it is annoying to find the starting point and the end point free to determine. So consider connecting this path first to a ring. So we can get the minimum answer of the ring directly. The smallest answer to the ring, that is, the path that is formed by not more than one black dot. So we can set a white point for the root, the whole subtrees tree is the black sub-tree deleted. The answer is twice times the number of edges in the tree, plus the points that need to be adjusted. A point needs to be adjusted, and the color is white if and only after it has been flipped several times.

Considering the deletion of a path from this ring, it is clear that one of the most contributing paths needs to be deleted. Find a need to adjust the point of deletion will reduce the contribution of \ (2\) , otherwise the contribution will not change, so long as the tree to find the diameter. Note that some special sentences need to be added.

ARC096 E Everything on it test instructions

A ramen restaurant with \ (n\) ingredients, a bowl of ramen can be arbitrarily added any ingredient, that is, a bowl of ramen can add \ (2^n\) different combinations of ingredients. One wants to come to the ramen restaurant to buy some bowls of ramen. Ask him how many different ways to meet the following two conditions:

  1. All the ingredients of the ramen you buy are different
  2. Each ingredient appears at least two times in all ramen purchases

\ (n \le 3000\).

Skills

The principle of tolerance is simplified and the violence is optimized.

Exercises

This restriction makes it easy to think about the principle of repulsion. If the direct violence is denounced, the enumeration of at least \ (i\) ingredients does not appear, at least \ (j\) The ingredients appear only once, and you need to enumerate one dimension \ (k\) to indicate how many sets of batching are divided for only one occurrence. This seems to be \ (O (n^4) \) ? Anyway, I will only do this complexity ... Partial points can be obtained.

Consider the enumeration of two-dimensional some waste, if the two-dimensional enumeration together, only one dimension, what happens?

Enumeration of at least \ (i\) kinds of batching occurs no more than once, and then enumerates this occurrence once the number is divided in order to \ (j\) A collection, the last enumeration appears once the number \ (k\) There will be one such equation.
\[ans_i = (2^{n-i}) ^j2^{2^{n-i}}\binom{n}{i}\sum_{k=j}^is (K,J) \binom{i}{k}\]
Note that \ (\displaystyle\sum_{k=j}^is (k,j) \binom{i}{k} = S (i + 1,j + 1) \) , so this equation can be \ (O (n) \) .

The formula for the Stirling number can be understood as adding a number of tokens, dividing the number of (i + 1\) into a \ (j + 1\) collection, and finally deleting the set where the number of tokens is located.

arc096f Sweet Alchemy Test Instructions

Given a tree of \ (n\) points and two parameters \ (d,x\), each point has a weight (w_i\) and cost \ (v_i\) . The weights for each point need to meet \ (w_{fa_i} \le w_i \le w_{fa_i} + d\) . Request \ (\displaystyle \sum_{i = 1}^{n} w_iv_i \le x\) and maximize \ (\displaystyle\sum_{i=1}^{n}w_i\) .

\ (n \le 50,x,d,v_i \le 10^9\) .

Skills

For a relatively small variety of weights, a large number of multiple knapsack special solution.

Exercises

To make a difference to the tree, it is easy to convert the original problem into a backpack model. The equivalent of a sub-tree of a point that you can add a value less than or equal to \ (d\) ( w\), and generate \ (w\sum v_i\) The cost, which requires maximization of weights and. How do you deal with this particular backpack model?

At the beginning of the backpack, there is a wrong idea: for weights of \ (v_i\) , the cost is \ (w_i\) a number of items, we calculated their cost-effective, greedy choice of the cost-effective part of the items. This is wrong because the goods can not be divided, so there will be free places to appear but can not be stuffed into better items. So we consider: under what circumstances can directly use cost-effective goods instead of low-cost goods?

Consider two items \ (v_i,w_i\) and \ (v_j,w_j\), where \ (\frac{v_i}{w_i} > \frac{v_j}{w_j}\) is \ (i\) price/performance ratio of items is higher than \ (j\). If we choose \ (v_i\) items \ (j\), instead of directly replaced by \ (v_j\) items \ (i\). The weights are equal, both \ (v_i \times v_j\), but less expensive:\ (v_j \times w_i < v_i\times w_j\). As a result we know: in the choice of more cost-effective items but no choice, the price of low-cost items up to select \ (v_i?1\) . and this \ (v\) range is very small, so we can take out each kind of items from the (min (n,d) \) pieces to carry out multiple backpacks, the remaining greedy.

The above is from the Twilight_sx ' s blog

The code is not written, and it doesn't mean anything.

Atcoder disorderly doing

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.