Learning Experience--day1

Source: Internet
Author: User

Today is the first day to attend the lecture. In the morning, I learned a part of the DP selection and the use of segment tree, the afternoon is a practice test. Here are the knowledge points learned today to do a clean-up and summary digestion.

Morning-DP Selection Talk

Part 1

sauce God treasure hunt (CDOJ1141)

Test instructions

The
sauce God came to a small island, the island has n a box. A total of 3 different keys, golden key, Silver keys and universal keys. The sauce God started with a golden key, B silver key and C master key. The first box has XI put the Golden Lock, yi the silver locks. Golden Key can only open the gold lock, silver key can only open silver locks, master key Two locks can be opened. The key to open the lock is immediately damaged and the sauce God loses the damaged key. The box has AI to the Golden Key, Bi put the silver key and CI to the master key, want to remove the key inside the box must open this xi+yi lock. The purpose of the sauce God is to keep the number of keys he has. Once the sauce God thought he had the most keys, he would not open the rest of the boxes.

Ideas:

Both the Golden key and the silver keys are specified and only specific locks can be opened. So in the same situation, we keep the universal key (greedy strategy) as much as possible. The policy is applied to DP, we define the state as dp[st][j]. ST is a binary number, using a form of pressure to save the state of the box, 1 indicates that the corresponding box has been opened, 0 indicates that it has not been opened. J holds the number of golden Keys held by the current sauce gods. DP stores the maximum number of master keys held by the current sauce gods. The silver key can be calculated by the number of golden keys, the number of master keys and the state of St. Each time the state transitions, the number of bits (treasure box number) that is currently zero is enumerated from St, and one is placed in turn to get the new state.

Part 2

Where is Bob (HDU5208)

Test instructions

Alice selects a number from [L1,R1] x,jsl See this number and takes a number y from [l2,r2] (Y may be the same as X). Finally they calculate the Z=x⊕y (⊙ is an XOR or operation). Alice wants Z as large as possible, while JSL wants Z as small as possible. Alice and JSL are smart, so what's the final z?
PS: If a, b two values are different, then the XOR result is 1. If the A and B two values are the same, the XOR result is 0.

Ideas:

There is a clear sequence of gameplay, and Alice knows that JSL is going to make z smaller by selecting as many as possible. So we can come up with a violent program: First enumerating I, representing the number Alice can select (L1≤I≤R1), and then enumeration J, which represents the number of JSL (L2≤J≤R2) that can be selected. The J (which simulates the selection of the JSL) in (R2-L2) j, which makes Z the smallest one, is then determined in (R1-L1) I to make the z largest I (Alice's Choice). Thereby getting the required Z. However, the complexity is very high, O (n²). The positive solution is DP, and the bitwise operation is used. Each time from the high-level decision (because the higher than the low weight, that is, the high position of one, low-zero effect is greater than the height of 0, low-total one), respectively, to reduce the number of two people selected the upper and lower bounds. Define DP[I][L1][R1][L2][R2], I means that the current operation to the I-bit, L1 and R1 respectively is Alice can select the number of the next and last, L2 and R2 respectively is JSL can select the number of the next and last. The actual value of the last value z is stored in the DP. When the state transitions, each bitwise decision is made. The first is that Alice has the initiative, and if the upper and lower bounds allow, our bit I can make decisions in 0 and 1 (that is, Alice determines the optimal (i.e. Z-max) of her choice by predicting the selection of JSL. If you select 1, then all the upper bounds of the number of bits lower than I are all set 0; Conversely, if you select 0, all the lower bits of the next term are all one. This can reduce the bounds of the upper and lower bounds continuously. And then the JSL,JSL will choose the number different from Alice, and we'll do the same for his upper and lower bounds as well. The value of the upper and lower bounds and Z values (that is, DP[0][L1][R1][L2][R2] are determined until the last pass.

Part 3

the journey of the sauce gods (CDOJ1140)

Test instructions

the sauce God is going to travel on a tree. The sauce God has made a travel plan, he wants to go to the node of M tree in order, A1,A2,A3,..., am. The sauce God has a car, each side of the tree can drive through, can also walk past, two methods need different time. If you choose to walk, the sauce God needs to stop the car at the junction, the next time he will drive, you must first return to the parking point to pick up the car. The sauce God and his car were at the beginning of the A1 knot, the sauce God will have to visit the end of the M node at least how much time.

Ideas:

First, it looks like a tree DP, which seems to need to follow the path of the tree. But the order in which the nodes actually need to go is prescribed, and it is said that the travel of the sauce gods has a prescribed path. So the first violent DFS will find the path, save it in the array, and then go to the array for DP. Define state Dp[i][j], I means the current sauce God on the first node, J indicates whether there is a car, DP represents the path minimum value in the case of I-J description. Then there are two options for the update of node I, the first is that there is no car at present, then dp[i][0] = min (dp[i-1][0], dp[i-1][1]) + walk_cost[i]; and now there are cars, there are two kinds of discussion, one is the current car is i-1 drive to the I node (dp[i][1] = dp[i-1][1] + car_cost[i]), the other is not before the car reached the I node when the car was picked up. For the case of picking up the car, can pick up the car in I, must be parked at the same point as I, and the point must be on the root node of the i-1, but after the same point as I may have more than one, we will record it as J1,J2,J3......JK. Then we can maintain a prefix and sum[i], indicating the cost of walking to the first point. Dp[i][1] = min (dp[jk][1] + sum[i]-SUM[JK])

Learning Experience--day1

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.