"Daily learning" "Condition shortest dij" POJ1062 expensive bride Price (2002 Zhejiang Province Team tryouts)

Source: Internet
Author: User

Time-consuming lessons fully reflect the carelessness caused by the mistake of the truth at first, I do not know why the array is out of bounds originally Minn and Ninj write reverse later again because the Duru function for the problem of repeated debugging must pay attention to the future


Let's put it in the title:

Title Description Description

Young explorers came to an Indian tribe. There he fell in love with the chief's daughter, so he went to Qiuqin to the chief. The sheikh asked him to use 10000 a gold coin as a dowry to promise to marry his daughter. The explorers could not get so many gold coins that they asked the chief to lower their demands. The sheikh said, "Well, if you can get me the High priest's Piao, I can just 8000 gold. If you can get his crystal ball, as long as the 5000 Gold is on the line. The explorer ran to the high priest and demanded Piao or a crystal ball, and the high priest asked him to change it with gold coins, or to get other things for him, he could lower the price. The explorers then ran to other places, and others made similar demands, either by exchanging coins directly or by finding something else to lower the price. But there's no need for explorers to change things with a variety of things, because they won't get a lower price. Explorers now need your help so that he can marry his sweetheart with the least amount of gold. And what he's going to tell you is that in this tribe, hierarchy is very strong. No direct contact will be made between two persons with a status gap exceeding a certain limit, including transactions. He is a foreigner, so he can not be subject to these restrictions. But if he trades with a lower-level person, the higher-status person will not trade with him, they think it is indirect contact and vice versa. So you need to give him the best plan after considering all the circumstances.

For the sake of convenience, we numbered all items starting from 1 , and the chief's promise was also regarded as an item, and the number was always 1. Each item has a corresponding price P, the master's status level L, as well as a series of alternatives Ti and the corresponding "offer" of the substitute Vi. If the difference in status between the two people exceeds M, it cannot be "indirectly traded". You have to figure out how much gold the adventurer needs at least to marry the chief's daughter.

Enter a description input Description

The input includes multiple test data. The first line of each test data is two integersM,N(1<=n<=100), which in turn represents the status level gap limit and the total number of items. Next, according to the number from small to large in turn givesNa description of the item. The description of each item starts with three non-negative integersP,L,X(X<n), which in turn represents the price of the item, the rank of the owner, and the total number of substitutes. NextXrow Each row consists of two integersTand theV, indicating the number of substitutes and "preferential prices", respectively.

outputs description output Description

For each test data, output the minimum number of coins needed in a single row.

sample input to sample

1 4

10000 3 2//The Chief's Promise

2 8000

3 5000

1000 2 1//Piao of the High Priest

4 200

3000 2 1//The High Priest's crystal ball

4 200

50 2 0//Other Items

Sample output Sample outputs

5250

It is easy to think of constructing a diagram, each node of the graph is an item, the right value is the price after the discount set the merchant to 0., find the shortest possible 1. Due to the level limit, the node must be 1 or less than the level of M, then for each of the upper and lower difference between the interval of M to find the shortest possible, and finally take the minimum value.

Easy to understand, draw a very bad picture, we gather live to look at


Put the code on:



The beginning of the round, the coming of the always come.

Welcome Floret to join the C party everyone family, undergraduate students you are now a person, your head ... I wish you all the best of the little flowers.


--the gentleman is knowledgeable and the Japanese are in the province, knowing and doing nothing.

"Daily learning" "Condition shortest dij" POJ1062 expensive bride Price (2002 Zhejiang Province Team tryouts)

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.