Topcoder srm301 div1 report

Source: Internet
Author: User

Topcoder srm301 div1 report

Match date:Tuesday, May 9, 2006

REPORT Date:Thursday, May 11,200 6

Preface:

I haven't done topcoder for a long time, mainly because SRM has poor time. Most of them will feel refreshed when I have classes or things, this is especially lucky to be in a group with Petr!

In total, it took a long time to submit the two statements. The first step was sent to challenge by Petr. Because the question was not reviewed, the challenge can be dropped using the test data. The second question took a long time to make changes and was not fully prepared. After coding is finished, it will drop the line and fail to enter challenge, so it will not be able to get more points.

Problem 250-indicatormotionreverse:

A simple simulation is just a matter of small details. Simulate various transformations to get a string a that contains all the changes, and then convert the repeated parts to the form of "Number of commands". Handle the commands that exceed 99 times with caution to get string B. Then, the first 99 of the target B is intercepted. If the number of B is greater than 99, 97 are intercepted and "..." is added.

Proble m 450-escapingjail:

The second question is full of ideas, but after clarifying the ideas, we will know that this question is essentially the diameter of the graph. The diameter of a graph is the longest shortest path, that is, the longest Shortest Path in all shortest paths.

After reading through the fancy introduction of the topic, you can think of using the Floyd algorithm to find the shortest path matrix and then obtain the maximum value. I just need to be careful when there is no limit between two points. I set it to integer. max_value.

Take the longest value as long as two cycles traverse the Shortest Path matrix and write down the longest two points.


Problem 1000-contextfreegrammars:

The last question is indeed a problem. A total of seven people passed the question. The test site should be grammar and dynamic planning. It is very difficult for people who are not familiar with grammar skills to pass this question.

I remember that I learned some syntax representation at the upper layer of the Compilation Principle Course (I do not remember it). This topic is about context-independent grammar (Context Free Grammar), CFG is simply composed of Non-terminator F and terminator T, and marks the starting non-Terminator s and a series of rules R. The relationship is like F :: = f | ft | T. For unrelated grammar, it requires only one F on the left.

The demonstration of a tree structure has provided the basic idea for solving this problem. The quick response should immediately come up with a DP or recursive method. If you do not handle the input of a question, we will get a directed acyclic graph. To facilitate our computing, if you are familiar with the Chomsky Paradigm (Chomsky Normal Form), You can convert CFG into CNF, and the result is a syntax structure like a binary tree. With this structure, it is undoubtedly a magic weapon to solve this task. The CNF paradigm ensures that each rule is F: = ff, F: = T, or S: = ε. . The following describes the conversion method:

To make the program smoother, consider F: = TT. Take a: = AB as an example. His CNF format is

A: = BCB: = ac: = B

For the binary tree structure, there is only one path between A and A, and only one path between A and B. The excess is B and C, so we can skillfully relax the CNF rules, that is to say, F ::= ft, F ::= TT, and f ::= TF are allowed.

After the loose CNF rules, we found that we only need to ensure that the right side of all rules is less than three, that is

If the right side is 1, it is retained directly. Otherwise

Set the left end symbol L

Scan from left to right {

Add the new rule l: = (current symbol) (new symbol t );

Set L = T;

}

Adjust the last two rules

In this way, we can obtain a rule that satisfies CNF after conversion. Note that if there is only one symbol on the right side, F: = f is meaningless and will not appear in irrelevant grammar, and F: = t needs to be specially labeled, to maintain one to two symbols on the right side, use a special symbol to represent its second symbol. If int is used, use-1.

Then we need to prepare the DP process. We maintain a three-dimensional array mem [I] [J] [K], which indicates starting from the position I of the word to be queried to the position J, the probability of a combination if the symbol K is used.

It is not hard to understand. For Rule A: = BC, there can be the following formula:

Mem [I] [J] [a] = sumk = 1... j-I (MEM [I] [I + k] [B] * mem [I + k] [J] [c])

-1 indicates that there is only one symbol in the right side of the rule, so-1 is skipped here.

Finally, determine the initialization conditions, and then just play the DP program as a child. Only t can be used as the leaf node of the binary tree, that is, Mem [I] [I + 1] [c] = 1 is available for each character C (position I) of the word to be queried.

Because there is only one symbol on the right side of the rule that is not processed in the DP equation, it is not easy to process in the DP equation, therefore, preprocessing is also required (this type of rule must be closer to the leaf node than other rules, so it must be done in advance ). That is, for each Rule F: = T, Mem [indexof (t)] [indexof (t) + 1] [f] ++, indexof (t) returns the position of T in the word to be queried.

Links:

My statistic:

Http://www.topcoder.com/stat? C = coder_room_stats & RD = 9822 & Cr = 20862220

SRM 301-problem set & analysis:

Http://www.topcoder.com/tc? Module = static & d1 = match_editorials & D2 = srm301

Graph diameter:

Http://mathworld.wolfram.com/GraphDiameter.html

Chomsky Normal Form:

Http://en.wikipedia.org/wiki/CYK_algorithm

Related Article

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.