The author is the same as me.

Expect to inspire yourself

Turn http://blog.csdn.net/yueqiq/article/details/7623176

First of all, I would like to say is that I am a very ordinary acmer, high school did not participate in any computer and mathematics contest experience, nor Ben so extraordinary talent, efforts so far have not achieved any results, I wrote this article, Just want to just enter the university or just into the ACM team of students A little help, I hope you can take a few detours, but also hope that you can help Hua Li to achieve the brilliance I have not achieved.

(1). Initial stage

I began to contact ACM from the sophomore, to say that the basic word is a freshman C language course, the language of the foundation is also weak, but the initial stage of ACM for language is not too high, as long as the school C language courses, basic can start your ACM process, but this is limited to the beginning of the time, When your ACM learns to a certain extent, the code length of each question will be more and more long, you will find some C + + language features can greatly simplify your code length and ideas, and C + + itself is a very important language, chewing C + + regardless of the level of ACM improvement, It is also very helpful to lay the groundwork for subsequent Windows programming. As for many people's so-called "do not know how to start" question, I also want to talk about my opinion, first of all you need to do is to pku some of the most basic simulation problems knocked, why? For a person who has not been in touch with programming in the past, the simulation problem can help you to improve the coding ability to a considerable extent, here the coding ability, will be your ideas or ideas, in the shortest possible time, with the most beautiful code to achieve it completely correctly, as to what is beautiful, I think you will experience it gradually in the course of your study. Here you may have to ask, where to find so many simulation questions? I think you just search google on the "PKU water problem" and other keywords, or directly look at our school's topic classification (want students can e-mail me to ask me to) can be found. So how many of these questions do you want to do? I think it's enough for a beginner to do a simple mock-up of about 30 lanes of ~50.

I started from the sophomore summer vacation in the PKU, because that time the main holding a "play" mentality, there is no plan for any game, the whole summer to play while learning, basically did not contact the algorithm problem, also cut dozens of of the simplest water problems, until summer camp ended there is no progress, Because the last sophomore in summer (at that time I was a freshman) and military training, so we all go home, after home to completely put ACM aside, basically did not touch, this decadent state has continued until the sophomore began quite a long time, I do not know what the reason I began to the relevant ( I really forget why it started to be relevant again, and began to contact with a variety of basic algorithms, at the beginning of the time is indeed more painful, but by the help of day brother and Ben Niu and the internet to see other people's Problem solving report finally to do 200 questions about, this time the sophomore is almost over, And I because of the reason for going abroad in winter vacation in the new Oriental TOEFL Training Course, ACM was I "Justified" on the side, and the whole winter vacation almost did not touch. and sophomore next semester after the beginning of my review of the TOEFL, until the end of the exam I began to the relevant career, in fact, from a strict sense, know this time I started a real plan and more diligent ACM training, has been training to the Shanghai Invitational. This is the first time I participated in the ACM competition, but also my first time with their own eyes to confirm the gap between themselves and others, this game to my shock is very big, the same is college students, the same age, but the gap is so big, it is really thoughtful. Knowing this time I really realized how much time I had wasted and realized that my level was so far from the others. Soon after that, the sophomore summer camp began, and these two months were the fastest progress I've made since ACM. Below, I want to put some of my experience and feelings of the problem to tell you, hope to be helpful to everyone.

(2). Key points of the problem

First of all, I think the most important thing is independent thinking and dare to try, so-called independent thinking, is not to do not come on the Internet to search others code habits, if it does not come out, you can try to ask others ideas, and then try to achieve their own, and so on to look at other people's code, learn some good place. And the so-called dare to try, is not afraid of the wrong, programming is a very special thing, he can verify the correctness of your theory on the spot, so, do not put the wrong hidden in the heart, open the computer to try, nature is clear, and only in this way, you can get happiness from each problem you complete. Secondly, it is to write the problem-solving report, the knowledge and the problems they encountered in this problem, and often comb sum up their learned knowledge, connect them together. When you stick to this place, I want to tell you that you are good, but please keep on, because the real fun in ACM is just the beginning, that is, the algorithm. I think, including me, most of the students will feel very confused, because in my experience, I almost every get a problem, most of the situation is a little thought, a little thought, wrote long time may be wrong, I think, encounter this situation you do not have to worry about, Because there are quite a lot of people like you, at the same time, there are many people among them have become quite good acmer, of course, this is also after they have paid a considerable effort to achieve results. So, I believe that as long as you persist, there will be a harvest of the day. So in the next big point, I'd like to say a few of the most important aspects you're going to conquer.

(3). Dynamic Planning (programming, hereinafter referred to as DP)

As the saying goes, to see a person's algorithm level, just look at him to do DP problem level is OK, and in the ACM This changeable arena, how the algorithm ups and downs, only DP almost never disappeared, if you ask me what type of question in the field appears the highest probability, I can not hesitate to tell you, is DP. It can also be seen that the status of DP is how important, so that almost every game will appear in the question, it should be difficult ah, why should we start with DP? Indeed, DP is very difficult, its variant, covering a wide range of knowledge, really let fancy but, but, I want to say how to get started DP problem. First of all, DP several of the most basic models, LCS (the longest common sub-sequence), LIS (Longest ascending subsequence), the largest common sub-segment and, the number of tower problems, matrix and so on a few of the most classic problems, we may be difficult to understand the beginning of the DP in the bottom-up, overlapping substructure and other basic ideas, For these questions can first look at someone else's code and the explanation of the book, and then again and again to understand, understand and then knock on their own code, if there is a place really do not understand, you can first put, to see other problems, back to think about the previous problem, perhaps there will be enlightened effect. After thoroughly understand a few classic problems with DP, you can do some variants of these classic problems, such as the largest common sub-segments and the variants of the largest and maximal m sub-segments, the longest common subsequence and the longest ascending subsequence, the longest common ascending subsequence, and so on. And can try to touch some of the important DP applications, the most important is the knapsack problem, the knapsack problem is a large branch of DP (the branch, I can not find other better words to describe him), also has a lot of variants, such as the most basic 01 backpack, as well as the expansion of the multi-backpack, complete backpack, Packet backpack, tree DP (This knowledge point I will introduce) in the application of a very many generalization backpack, and so on, I will be the most basic 01 backpack, multi-pack and full backpack, the first is the simplest 01 backpack, pseudo-code as follows:

For I=1..N

For V=v. 0

f[v]=max{F[v], f[V-c[i]] + w[i]}

Why do we have to push backwards here? In fact, the reason is very simple, because here is actually using a similar rolling array concept, but he even 2 arrays are not open, only need to open an array on it, this is why? Because the value of f[i][v] in a traditional two-dimensional array is derived from Max (F[i-1][v], f[i-1][v-c[i], + w[i), the value of each f[v] is obtained by F[v '] (V ' <=v) in the upper loop, so after changing to a one-dimensional array, If from small to cycle, after the calculation completed F[V], will be calculated F[v '] (V ' >=v) error occurs, because the original calculation F[v '] required in the upper loop F[v] value has been overwritten by the new value, it must be from large to small loop. Next is the multi-pack, completely can be turned into 01 knapsack problem, but the same value of the same kind of goods as multiple values of different kinds of goods, that is more than 01 backpack a heavy cycle, it is important to note that the two-layer cycle from large to small, the principle and 01 backpack similar. Finally, the complete knapsack problem, pseudo code is as follows:

For I=1..N

For V=0..V

f[v]=max{F[v], f[V-c[i]] + w[i]}

This pseudo-code is different from the pseudo-code of the 01 backpack, which only has a V cycle order. Why is such a change feasible? First think about why the 01 backpack to follow V=v. 0 in reverse order to cycle. This is due to the fact that the state in the first cycle of f[i][v] is recursive by state F[i-1][v-c[i]]. In other words, this is to ensure that each item is selected only once, to ensure that when considering the strategy of "Select Item I", it is based on a sub-result (F[i-1][v-c[i]) that has not been selected for the article I item. And now the full backpack is a unique feature of each item can be selected unlimited, so in the consideration of the "optional item I" This strategy, but I need a may have been selected in the sub-results of the item I (F[i][v-c[i]), so you can and must be in the order of v= 0..V cycle. This is the reason why this simple procedure is set up. Here I recommend to you Zhejiang University's DD Cow "backpack Nine", is the introduction of backpacks and improve the most classic information. Now it is necessary to talk about the tree DP, the tree DP is actually DP, but is built on the tree model of DP, but the tree-type DP said although simple, is really a very difficult DP in a knowledge point, to understand, do more problems. Finally, the state compression DP, which is also a DP of a difficult point, the so-called state refers to the use of binary or other binary number to represent the state to achieve the purpose of space compression, this kind of state design is generally very clever, and the number of bits involved in the coding ability is also a considerable challenge, In the state compression DP is a memory search (so-called memory search, is a DP of another recursive implementation of the form, that is, the so-called top-down) to achieve, but also involves the search of knowledge points, suggestions and so on learning the relevant content and then back to learn this knowledge point. The classic problem of state compression is the board cover problem, artillery position and so on.

(4). Search (including DFS, BFS, a *)

Search is also a fairly important part of ACM, involving a fairly wide range, first and foremost the most basic depth-first search for DFS, the so-called DFS, In fact, through the recursive way to enumerate all possible to get the results we want, and a very important technique in the search is pruning, that is, artificially delete some unnecessary search, thereby improving the efficiency of our program, DFS Classic problem has the most famous eight queens for the title, sticks and so on. In fact, the DFS problem is too much, pku on a lot of questions can be for our practiced hand. The other is breadth-first search (BFS), breadth-first search is the basic idea is to build a queue (the queue is a basic data structure, I will explain in the next section), and then each time out of the queue out of a point to expand all the possibilities, and then the liberation of our needs into the queue waiting for the next expansion, has been extended to find the answer or can not expand so far, BFS classic problems have vault problem, eight digital and so on. BFS has a very common technique or optimization, that is, two-way BFS, the idea is the same, is the beginning and the end of the expansion, until the intersection of the time means to find the answer, so that compared to the ordinary BFS can save a lot of space and time. BFS also has another common extension, is the priority queue BFS, the so-called priority queue (priority queue is an implementation of the queue, I will also explain in the next section), is always keep the queue of the first element is the smallest, so that each extension is the current smallest element, here the so-called smallest, Actually refers to the current seemingly optimal solution, using such a greedy method, to speed up our search for the speed of the answer, of course, the specific efficiency also depends on the data of the topic. Said so many priority team BFS, is actually a * a special case, a * Chinese name is heuristic search, is a commonly used in artificial intelligence search technology, A * The most basic application is to find the shortest way, through a valuation function of the current point to make a value assessment, Then we put these expanded points into a priority queue according to their value, then each time we take out the first element of the team is not our current best hope of a point? If using STL (C + + Standard Template Library, the same will be explained in the next section) to achieve the priority queue, a * compared to the BFS code volume almost no increase, nothing more than a valuation function, but the problem is how to better design a valuation function, a * of the classic problem has a snake, eight digital.

(5). STL for C + + applications

STL is the standard Template Library of C + +, which provides us with quite a lot of out-of-the-box library functions and data structures, STL can greatly shorten the length of our code, has greatly reduced our probability of error. Then you may be wondering why I still hate STL? The reason is simple, we have to pay a considerable price, that is efficiency. Here's a brief introduction to STL's Simple application in ACM. The first is the library function in the STL, where we have our most commonly used sort sorting function, there are some lookup functions such as Find,lower_bound and upper_bound to simplify our code, and the most common is the sequential container and the associated container, In fact, the sequential container can be quite a considerable substitute for some common basic data structures such as vectors can replace the variable length of the array (can simply implement the adjacency table), list can replace the list, stack can replace the stack, deque can replace the double-ended queue, priority_ The queue can replace the priority queue we mentioned earlier, and the map in the associative container can implement an index between any two types of data, and set can find out whether an element exists in a collection.

(6). Data structure of the basic chapter

The data structure is widely used in ACM, but the problem of examining a data structure based on a single topic is relatively small, which is generally a supplementary function, such as the priority queue we mentioned earlier, and a very common hash, as we mentioned before, in the process of BFS, We need to filter out the points we need to put in the queue, which are the unwanted points, in general, refers to the point that has the same state as a previously searched point, and the same method of judging whether the state is the same is often using hash to save the previously searched state. and determine whether the state of the point at each extension is already present, and if it does not exist, we'll put it in the queue.

(7). Improvement of data structure (including and check sets, tree array, segment tree)

The data structure also has some relatively high-level applications, these points of knowledge may be as a knowledge point alone, first of all, and check set, and the basic idea is to select an element in a set as a set of elements, through the operation of these representative elements to achieve the merging between the set of operations, In the kruscal of the classical algorithm for the minimum spanning tree, it is also used to determine whether two elements belong to the same edge, which is mentioned in the summary of the next part of the graph theory. And check set also have a lot of topics can do, classic questions have food chain, gay insects, gangs and so on, and check set there is a variant is to remove an element from a set, we know that the common and check set is not included in the function of deleting elements, and the implementation of the deletion element is actually very simple, is to create an index on each point, at the beginning each point index points to themselves, when an element is deleted, the first to create a new not belong to any set of new points, in the deleted point index to the new point. The second part is a tree-like array, he supports the complexity of O (NLOGN) to calculate the sum of the elements within the interval, his mind is very ingenious, is the tree-like array summary: Suppose c[] is a tree-like array, a[] as the original array, then there is a relationship between the two, C[i] represents the significance of a[i K-Elements and (k is the number of the 0 that the tail contains when I is converted into a binary). The nature of the bitwise operation can be obtained: for I,,i& (-i) = 2^k, then the basic function of the tree array can be understood. The tree-like array also has more questions, pku_1990,pku_2828,pku_2155 and so on. Finally, I would like to say the segment tree, line segment tree is a very powerful data structure, he supports in O (NLOGN) of the complexity of the interval range of elements to modify, delete and so on, and check set, the tree array is different, the implementation of the segment tree is very flexible, a problem, almost no stereotypes, of course, The most basic idea is that each node represents an interval, and the left and right sub-trees are divided by a half and a half, which are recursively defined until they are a point or contain a unit. Line Tree also has a few basic models and classic examples, first I want to talk about is a relatively simple but very classic line segment tree application to introduce the concept of line segment tree, such as a series of problems, namely the dyeing problem. Take pku_2777 as an example, the main idea is that there is a piece of the length of the board of L cm, each centimeter can be regarded as a unit interval, the type of color by the number, the beginning of each interval color is 1, and now to the tree O operations, operation there are two, the first is the interval a to B color is dyed C color, The second is to ask the range A to B a total of several colors. The simplest idea might be to open an array of length L a[], while a[i] is the color of the first I, but is it feasible? Let's take a look at the data range, the range of L is 100,000, the range of O is also 100,000, then the complexity of the algorithm is O (LO), obviously time-out, so we choose to use a line segment tree to help us solve this problem, in fact, the word line tree is not very good description of its powerful function, I prefer his academic nouns-interval tree, like other trees, He can perform maintenance operations on the tree in O (LOGL), which means he can perform a series of operations on an interval of time within O (LOGL). It is this high efficiency of line-segment tree that he has been fully applied in RMQ problems, and in solving a series of problems, such as rectangular area and perimeter. Here I want to talk about the RMQ problem (that is, the problem of finding the maximum or lowest value in the interval), it is well known that the RMQ problem has an O (NLOGN) preprocessing and an O (1) time to find out the maximum or minimum value in any interval offline algorithm (so-called offline, That is, can not dynamically change or insert the value of the interval in the process of seeking, that is, the St (Sparse Table) algorithm, in contrast, the segment tree does not have the advantage of efficiency, but there is a limitation of St algorithm, is not support online operation, and the line tree does not have this limitation, it can be found, the strong segment tree Segment Tree also has a high-level application is the maintenance of the interval of the most valuable information, the corresponding classic problems have a lot, also have a certain degree of difficulty, pku_2482,pku_1151 (to find the area of N-rectangle merging), pku_1177 (for n-Rectangle after the merger of the perimeter) and so on. The basic idea to grasp the most value of maintenance is to maintain each subtree recursively, using the information of the subtree to maintain the father.

(8). String (including KMP algorithm, trie tree, suffix array)

The string processing is also a considerable piece of knowledge in ACM, but also has a considerable practical application surface, in fact, the knowledge of the string of my own contact is relatively small, so can only briefly talk about a few of the most basic algorithm, KMP algorithm is two strings matching the most basic linear algorithm, The core of the algorithm is the understanding of the next array, which is preprocessed for a string, which successfully reduces the complexity of the two strings to a linear level. But the KMP algorithm can only be matched between two strings, what if we want to match multiple strings? Trie help us solve this problem, trie is actually a letter tree, each node of the tree has 26 English letters, by marking these nodes to insert a string, after inserting n strings, So we can match the n strings at the same time, and we can do the same for the N string, and the trie tree has a big drawback, that is, the space he needs is a number of levels, and all the usual strings are more than 15 in length, we should consider other methods. The last is the suffix array, the main essence of the algorithm is the understanding and application of the height array, two articles in the national team paper is specifically about the suffix array, I do not repeat here.

(9). Graph theory (including the shortest path, minimum spanning tree, strong connected components and other knowledge points)

The reason to put the content of the graph theory is completely because the knowledge point of the graph theory is too much, the aspects involved is too wide, I am here to pick a few of my topic to do more than a simple summary. The first is the shortest circuit, mainly divided into multiple sources, the quickest way, with the algorithm is very classical Floyd algorithm, the complexity of O (n^3), the implementation is quite simple, mainly is the idea of DP. There are single source shortest, the most primitive method is Bellman-ford, but the probability of using the algorithm is not high, because he has a very good alternative, is the implementation of SPFA,SPFA is a bit similar to the wide search, the code is very short, For Bellman-ford to ask whether there is a negative ring problem can be completely replaced, and in the sparse graph to find the shortest-circuit efficiency is even higher than the priority queue optimized Dijkstra, is indeed a useful good thing. Of course, the most famous Dijkstra algorithm is absolutely not to mention, the algorithm is our shortest path when the most commonly used algorithm, but because he took advantage of the greedy criteria, so must pay attention to Dijkstra can not deal with negative right side of the graph, and Dijkstra also has a few very classic variants, One is to extend the Dijkstra to two-dimensional to find a short-circuit, the other is to use a * to find a short-circuit, whether we notice, learned in the back, the demarcation between different pieces of knowledge is increasingly unclear, because our brains are gradually forming a knowledge network, each of the knowledge points are organically connected together. The second big point is the smallest spanning tree, this kind of problem also has two well-known algorithm, applies to the dense graph prim algorithm and applies to the sparse graph the kruscal algorithm (the algorithm which uses and the search set), the smallest spanning tree also has some classical variant, the as follows niche becomes the tree, the minimum restriction degree spanning tree and so on. Another kind of very important problem is the binary matching problem, the problem involves the knowledge point is also quite many, to seek the maximum match of the right binary graph has the most classical Hungarian algorithm as well as the least/large matching km algorithm for the weighted binary graph, and the knowledge points derived from the maximum matching number of the non-weighted binary graphs have minimal coverage problem , the minimum path coverage problem and so on, this piece of content concept is relatively strong, in fact, the most important feature of graph theory is strong concept, many variants, if not deeply understand every problem and its classic algorithm, really can not strain. The most is the Euler circuit problem, this kind of problem is relatively simple, is nothing more than two, one is to judge whether there is a Euler circuit in the diagram, and then one is to find out the European pull circuit in one, the realization is very simple, a Dfs can be completed. There is also strong connectivity components, the core of the algorithm is to a graph to find a strong connected component after the contraction point, so that a graph into a undirected graph, so as to facilitate the operation of our next. The last chunk is the network flow, the content I involved is also relatively few, mainly is a few of the classical algorithm for network flow, such asHlpp,isap,ek and so on, the network flow variant is also very much, need to impose practice.

(10). ACM Final return to the contest chapter

I have participated in the formal game has two games, one is sophomore under the Shanghai Invitational Tournament, another is a junior on the Hefei regional competition, because the level is limited, after all, still only took two bronze medals, the following I want to talk about the team's personal feelings, the first is the composition of the players, At least a person with strong coding ability is mainly responsible for tapping the code to increase the speed of the simple problem, the other is a strong foundation of mathematics, because ACM now more and more like the math problem, and the mathematical good often ideas will be more open, can provide ideas for the whole team, and then there is a wide range of algorithms contact people, This kind of person contact algorithm is more, the relevance number also is more, although probably not which aspect is particularly strong, but its rich to do the problem experience to ensure his to a problem of algorithm olfactory, can for the whole team to indicate direction. Speaking of which, my summary is going to be over, I hope you can get help from it.

Go to ACM course sticky posts