#P10332. [UESTCPC 2024] 一站到底
[UESTCPC 2024] 一站到底
Problem Description
Suppose you are Li Hua, a student at University of Electronic Science and Technology of China. In an episode of “One Stand to the End” in the year 4202, you participate as a contestant in the recording of the show. Unlike the rules from more than 2000 years ago, the show will not have stages where contestants duel in pairs and compete to buzz in or take turns answering. Instead, each contestant answers questions in a solo format. The specific rules are as follows.
Before your answering stage begins, the system will draw questions from the question bank. Each question has a score based on its difficulty. The host will announce all question statements and their scores at the beginning, and then your answering stage starts.
To make the show more interesting, during the answering stage, you cannot choose the order of questions freely. Specifically, except for Question , every other question has exactly one prerequisite question. You can answer a question only after you have correctly answered its prerequisite. The production team guarantees that the prerequisite question index of Question is always less than .
In addition, if you submit a wrong answer when answering a question, the floor beneath you will open immediately, you will fall, and your answering stage ends. The sum of the scores of all previously answered correctly questions is your final score. If you answer all questions correctly, then the sum of the scores of all questions is your final score.
Now you have read all the questions. Based on your knowledge, you estimate the probability that you will answer each question correctly. You need to design the best problem-solving strategy in the shortest time to maximize your expected score. Please output this score, and write an English essay of at least 120 words about the experience of participating in this show.
Input Format
The first line contains a positive integer , representing the number of questions.
The next line contains positive integers , where is the score of Question .
The next line contains real numbers , where is the probability that you answer Question correctly.
The next line contains positive integers , where is the index of the prerequisite question for Question .
Output Format
Output one real number, representing the expected score under the optimal strategy.
Suppose your output is and the correct answer is . Your answer will be considered correct if and only if .
5
5 4 3 2 1
0.9 0.89 0.88 0.87 0.86
1 1 2 2
11.572522416
Hint
In the sample, the questions with higher scores also have higher probabilities of being answered correctly, so it is clearly optimal to answer in the order .
Translated by ChatGPT 5