Bzoj1003 (Short Circuit + dp)

Source: Internet
Author: User

1003: [zjoi2006] Logistics and Transportation transtime limit: 10 sec memory limit: 162 MB
Submit: 3479 solved: 1416
[Submit] [Status] Description

The logistics company wants to ship a batch of goods from Pier A to Terminal B. Because the cargo volume is large, it takes n days to complete the operation. In the process of cargo transportation, it is generally necessary to stop several docks. Logistics companies usually design a fixed transportation route to strictly manage and track the entire transportation process. Due to various factors, sometimes the cargo cannot be loaded or unloaded at a certain pier. At this time, you must modify the transportation route so that the goods can arrive at the destination on time. However, modifying the route is a very troublesome task and will incur additional costs. Therefore, the logistics company wants to set up a transportation plan for N days to minimize the total cost.

Input

The first row contains four integers, n (1 <= n <= 100), m (1 <= m <= 20), K, and E. N indicates the number of days required for cargo transportation, M indicates the total number of terminals, and K indicates the cost required for each modification of the transportation route. Next, each line of line E is a route description, which contains three integers, indicating the number of two terminals connected to the route and the length of the route (> 0 ). Pier A is 1 and pier B is M. The transportation fee per unit is 1. The route is bidirectional. The next row is an integer d, and the next row of D is three integers p (1 <p <m), A, B (1 <= A <= B <= N ). It indicates that goods (including head and tail) cannot be loaded and loaded from day A to day B of the pier numbered p ). The same pier may be unavailable for multiple time periods. However, there is at least one transportation route from Pier A to pier B at any time.

Output

An integer is included to indicate the minimum total cost. Total cost = the sum of N-day transportation route lengths + K * The number of transportation routes changed.

Sample input5 5 10 8
1 2 1
1 3 3
1 4 2
2 3 2
2 4 4
3 4 1
3 5 2
4 5 2
4
2 2 3
3 1 1
3 3 3
4 4 5
Sample output32hint

Take 1-4-5 for the first three days, and 1-3-5 for the next two days. The total cost is (2 + 2) x 3 + (3 + 2) * 2 + 10 = 32


Question: RT
Train of Thought: pre-process the minimum cost of not changing the route for all interval days
Use DP [I] [J] to represent the minimum cost of the route from day I to day J without changing the route (use DJs or spfa to run the shortest path each time)
Then dp2 [I] is used to indicate the minimum cost until the day I.
Transfer to dp2 [I] = min (dp2 [J] + dp [J + 1] [I] + k)

Bzoj1003 (Short Circuit + dp)

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.