luogu#P4853. yyf hates dagequ

    ID: 3805 远端评测题 666ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP递推2018洛谷原创Special Judge期望

yyf hates dagequ

Background

The unlucky player yyf, guided by dew, drew some pretty good cards, but he is still too unlucky. For randomly triggered skills, he always fails to trigger them. yyf wants to know how unlucky he really is, so he asks you to compute his expected score and compare it with his actual score.

The precision limit for this problem has been relaxed, and both Wrong Answer and Correct Answer are shown. Please do not design solutions based on this.

Problem Description

You are given some card skills. There are 22 types of skills:

  1. Bonus score: every time you reach a combo of cc, there is a p%p\% chance to gain ss points.
  2. Judgment change: every time you reach a combo of cc, there is a p%p\% chance to trigger a “strong judgment effect”, lasting for tt rhythm icons (suppose that when the combo count is a multiple of cc, it corresponds to the ii-th rhythm icon; then the strong judgment effect is applied on the [i+1,i+t][i+1,i+t] rhythm icons).

These skills have a chance to trigger when the combo count is a multiple of cc and the combo count is not 00. Multiple skills may trigger at the same time.

Among them, there are score\mathrm{score} bonus-score skills and judge\mathrm{judge} judgment-change skills.

You are also given nn rhythm icons (yyf hits them in the given order). yyf’s original (relative to the result after applying the “strong judgment effect”) hit result for each icon is one of 22, 11, or 00.

During the duration of a “strong judgment effect”, all hit results 11 are treated as hit results 22. Hit result 00 is still treated as 00, and hit result 22 is still treated as 22. Unless otherwise stated, “hit result” below refers to the corrected hit result.

The definition of “combo count” is the number of consecutive hit results equal to 22 so far (if the current hit result is 22, then this hit is also counted into the current combo; otherwise, the current combo becomes 00).

Multiple “strong judgment effects” can overlap, but their durations do not stack. (Let the remaining time of the current “strong judgment effect” be t1t_1. If two “strong judgment effects” are triggered simultaneously now, with durations t2t_2 and t3t_3, then at the next hit, the remaining time becomes max(t11,t2,t3)\max(t_1-1,t_2,t_3).)

The score of one hit equals the hit result multiplied by the current combo plus one. That is, let the current hit result be xx and the current combo be combo\mathrm{combo}, then the score of this hit is x(combo+1)\mathrm{x*(combo+1)}.

The final score is the sum of the scores of all hits (a total of nn hits) plus the total bonus points gained from bonus-score skills.

Please compute the expected final score for yyf in this song.

Input Format

The first line contains three non-negative integers n score judge\mathrm{n\ score\ judge}.

The next score\mathrm{score} lines each contain three positive integers c p sc\ p\ s, describing a bonus-score skill.

The next judge\mathrm{judge} lines each contain three positive integers c p tc\ p\ t, describing a judgment-change skill.

The last line contains nn integers, each in [0,2][0,2]. The ii-th integer represents the original result of the ii-th hit.

Output Format

Output one real number in a single line, representing yyf’s expected score. Your answer is accepted if the relative error is within 10510^{-5}.

4 1 1
3 70 3
2 20 1
2 2 1 1
13.82
5 0 2
2 60 1
2 10 2
2 2 1 1 1
19.084
5 0 0
2 1 0 2 2
15

Hint

Constraints

For all test points: 5n10005 \le n \le 1000, 0score10000 \le \mathrm{score} \le 1000, 0judge10000 \le \mathrm{judge} \le 1000, 1c51 \le c \le 5, 1p991 \le p \le 99, 1s101 \le s \le 10, 1t51 \le t \le 5.

Test Point ID nn score\mathrm{score} judge\mathrm{judge} Special Constraint Test Point ID nn score\mathrm{score} judge\mathrm{judge} Special Constraint
11 10001000  0 \ \,0\ \, All aia_i are 22 1111 10001000  0 \ \,0\ \,  9 \ \,9\ \, None
22 00 00 None 1212 22
33 11 1313 33 33
44 99 1414 66
55 10001000 1515 11 88 All cc are 11
66 5050 11 1616 00 99
77 22 1717 10001000
88 44 1818
99 00 99 1919 None
1010 44 55 2020

Sample 1 Explanation

Sample 2 Explanation

Sample 3 Explanation

The first hit scores 44 points, the second hit scores 11 point, the third hit scores 00 points, the fourth hit scores 44 points, and the fifth hit scores 66 points.

Translated by ChatGPT 5