#P1850. [NOIP 2016 提高组] 换教室

    ID: 803 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2016NOIp 提高组期望

[NOIP 2016 提高组] 换教室

Description

For Niuniu, who has just entered university, the first problem he faces is how to apply for suitable courses according to the actual situation.

Among the selectable courses, there are 2n2n classes scheduled across nn time slots. In the ii-th time slot (1in1 \le i \le n), two classes with the same content are held simultaneously at different locations. Niuniu is pre-assigned to attend the class in classroom cic_i, while the other class is in classroom did_i.

Without submitting any applications, students follow the order of time slots to complete all nn scheduled classes one by one. If a student wants to switch the classroom for the ii-th class, they need to submit an application. If the application is approved, the student will attend the class in classroom did_i during the ii-th time slot; otherwise, they will still attend in classroom cic_i.

Because there are too many requests to switch classrooms, an application may not be approved. Through calculation, Niuniu finds that when applying to switch the classroom for the ii-th class, the probability that the application is approved is a known real number kik_i, and the approval events for different classes are independent.

The school stipulates that all applications must be submitted once before the start of the term, and each person may choose to apply for at most mm classes. This means that Niuniu must decide all at once whether to apply to switch the classroom for each class, and cannot decide whether to apply for other classes based on the approval results of some classes. Niuniu can apply for the mm classes he most wants to switch, he may also use fewer than mm application opportunities, or even apply for none.

Because different classes may be arranged in different classrooms, Niuniu needs to use break time to travel from one classroom to another.

Niuniu’s university has vv classrooms and ee roads. Each road connects two classrooms and is bidirectional. Because road lengths and congestion vary, the stamina consumed when traversing different roads may differ. After the ii-th class ends (1in11 \le i \le n - 1), Niuniu will depart from the classroom of that class and choose a path with the minimum stamina cost to reach the classroom of the next class.

Now Niuniu wants to know which classes he should apply for so that the expected value of the total stamina cost due to moving between classrooms is minimized. Please help him compute this minimum value.

Input Format

The first line contains four integers n,m,v,en, m, v, e. nn is the number of time slots in this term; mm is the maximum number of classes for which Niuniu may apply to switch classrooms; vv is the number of classrooms in the school; ee is the number of roads in the school.

The second line contains nn positive integers. The ii-th (1in1 \le i \le n) integer is cic_i, the classroom where Niuniu is scheduled to attend in the ii-th time slot. It is guaranteed that 1civ1 \le c_i \le v.

The third line contains nn positive integers. The ii-th (1in1 \le i \le n) integer is did_i, the classroom of the other class with the same content in the ii-th time slot. It is guaranteed that 1div1 \le d_i \le v.

The fourth line contains nn real numbers. The ii-th (1in1 \le i \le n) real number is kik_i, the probability that Niuniu’s application to switch the classroom in the ii-th time slot is approved. It is guaranteed that 0ki10 \le k_i \le 1.

The next ee lines each contain three positive integers aj,bj,wja_j, b_j, w_j, indicating a bidirectional road connecting classrooms aja_j and bjb_j, and traversing this road consumes stamina wjw_j. It is guaranteed that 1aj,bjv1 \le a_j, b_j \le v and 1wj1001 \le w_j \le 100.

It is guaranteed that 1n20001 \le n \le 2000, 0m20000 \le m \le 2000, 1v3001 \le v \le 300, and 0e900000 \le e \le 90000.

It is guaranteed that using the school’s roads, every classroom is reachable from any other classroom.

It is guaranteed that each input real number has at most 33 decimal places.

Output Format

Output one line containing a real number, rounded to exactly 22 decimal places, which is the answer. Your output must be exactly the same as the standard output to be considered correct.

The testdata guarantees that the absolute difference between the rounded answer and the exact answer is at most 4×1034 \times 10^{-3}. (If you do not know what floating-point error is, you can understand this as: for most algorithms, you can normally use floating-point types without special handling.)

3 2 3 3
2 1 2
1 2 1
0.8 0.2 0.5 
1 2 5
1 3 3
2 3 1

2.80

Hint

Sample 1 explanation.

All feasible application plans and their expected stamina costs are as follows:

  • No application submitted. The expected stamina cost is 8.08.0.
Time slots approved Probability Stamina cost
None 1.01.0 88
  • Apply to switch the classroom in the 11-st time slot. The expected stamina cost is 4.84.8.
Time slots approved Probability Stamina cost
11 0.80.8 44
None 0.20.2 88
  • Apply to switch the classroom in the 22-nd time slot. The expected stamina cost is 6.46.4.
Time slots approved Probability Stamina cost
22 0.20.2 00
None 0.80.8 88
  • Apply to switch the classroom in the 33-rd time slot. The expected stamina cost is 6.06.0.
Time slots approved Probability Stamina cost
33 0.50.5 44
None 88
  • Apply to switch the classroom in the 11-st and 22-nd time slots. The expected stamina cost is 4.484.48.
Time slots approved Probability Stamina cost
1,21,2 0.160.16 44
11 0.640.64
22 0.040.04 00
None 0.160.16 88
  • Apply to switch the classroom in the 11-st and 33-rd time slots. The expected stamina cost is 2.82.8.
Time slots approved Probability Stamina cost
1,31,3 0.40.4 00
11 44
33 0.10.1
None 88
  • Apply to switch the classroom in the 22-nd and 33-rd time slots. The expected stamina cost is 5.25.2.
Time slots approved Probability Stamina cost
2,32,3 0.10.1 44
22 00
33 0.40.4 44
None 88

Therefore, the optimal plan is to apply to switch the classroom in the 11-st and 33-rd time slots. The expected stamina cost is 2.82.8.

Notes.

  1. There may be multiple bidirectional roads connecting the same pair of classrooms. It is also possible for a road to connect a classroom to itself.
  2. Please distinguish the meanings of n,m,v,en, m, v, e. nn is not the number of classrooms, and mm is not the number of roads.

Constraints and Notes.

Test set ID nn \le mm \le vv \le Has Special Property 1 Has Special Property 2
1 11 300300 ×\times
2 22 00 2020
3 11 100100
4 22 300300
5 33 00 2020 \surd \surd
6 11 100100 ×\times
7 22 300300 ×\times
8 1010 00 \surd \surd
9 11 2020 ×\times
10 22 100100 ×\times
11 1010 300300 \surd
12 2020 00 2020 \surd ×\times
13 11 100100 ×\times
14 22 300300 \surd
15 2020 ×\times \surd
16 300300 00 2020 ×\times
17 11 100100
18 22 300300 \surd \surd
19 300300 ×\times
20 20002000 00 2020 ×\times
21 11
22 22 100100
23 20002000
24 300300
25

Special Property 1: For any two distinct nodes u,vu, v in the graph, there exists a minimum-stamina path that consists of only one road.

Special Property 2: For all 1in1 \le i \le n, ki=1k_i = 1.

Translated by ChatGPT 5