#P5154. 数列游戏
数列游戏
Description
{{The rules are as follows:
LJC writes down two sequences of positive integers and , both of length . The two sequences are paired one-to-one, that is, for each there is a pair .
Each time, HKE may choose an adjacent pair and . If they are not coprime (i.e., ), he may remove this pair and gain points.
The removed pair is simultaneously deleted from both sequences, and the sequences are compacted (the remaining elements shift left).
When all adjacent pairs in the sequence are coprime, the game ends. HKE wants to know the maximum total score he can obtain.}}
Input Format
{{- Line 1: an integer (the length of the sequences).
- Line 2: integers, representing .
- Line 3: integers, representing .}}
Output Format
{{- Output one integer, the maximum total score HKE can obtain.}}
6
9 8 6 5 6 3
11 19 12 17 18 15
64
//解释:擦去A[2],A[3]与A[5],A[6],得分为64
Hint
{{Sample Explanation:
- First remove and , gaining points.
- After the update, they become and .
- Then remove and , gaining points.
- The total score is .
Constraints:
- For 30% of the testdata, .
- For 60% of the testdata, .
- For 80% of the testdata, .
- For 100% of the testdata, .
- It is guaranteed that .}}
Translated by ChatGPT 5
京公网安备 11011102002149号