CF1810G.The Maximum Prefix
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You're going to generate an array a with a length of at most n, where each ai equals either 1 or −1.
You generate this array in the following way.
- First, you choose some integer k (1≤k≤n), which decides the length of a.
- Then, for each i (1≤i≤k), you set ai=1 with probability pi, otherwise set ai=−1 (with probability 1−pi).
After the array is generated, you calculate si=a1+a2+a3+…+ai. Specially, s0=0. Then you let S equal to i=0maxksi. That is, S is the maximum prefix sum of the array a.
You are given n+1 integers h0,h1,…,hn. The score of an array a with maximum prefix sum S is hS. Now, for each k, you want to know the expected score for an array of length k modulo 109+7.
你将生成一个长度至多为 n 的数组 a,其中每个元素 ai 的值为 1 或 −1。
该数组按如下方式生成:
- 首先,你选择某个整数 k(满足 1≤k≤n),它决定数组 a 的长度;
- 然后,对每个 i(满足 1≤i≤k),以概率 pi 令 ai=1,否则以概率 1−pi 令 ai=−1。
数组生成完毕后,你计算前缀和 si=a1+a2+a3+…+ai。特别地,定义 s0=0。再令 S=i=0maxksi,即 S 是数组 a 的最大前缀和。
现给定 n+1 个整数 h0,h1,…,hn。若数组 a 的最大前缀和为 S,则其得分为 hS。现在,对每个 k,你需要计算长度为 k 的数组的期望得分(对 109+7 取模)。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤5000) — the number of test cases. Their description follows.
The first line contains an integer n (1≤n≤5000).
Then for the following n lines, each line contains two integers xi and yi (0≤xi<109+7, 1≤yi<109+7, xi≤yi), indicating pi=yixi.
The next line contains n+1 integers h0,h1,…,hn (0≤hi<109+7).
It is guaranteed that the sum of n over all test cases does not exceed 5000.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤5000),表示测试用例的数量。随后是这些测试用例的描述。
第一行包含一个整数 n(1≤n≤5000)。
接下来的 n 行中,每行包含两个整数 xi 和 yi(0≤xi<109+7,1≤yi<109+7,且 xi≤yi),表示 pi=yixi。
下一行包含 n+1 个整数 h0,h1,…,hn(0≤hi<109+7)。
保证所有测试用例中 n 的总和不超过 5000。
输出格式
For each test case, output n integers in one single line, the i-th of which denotes the expected score for an array of length i, modulo 109+7.
Formally, let M=109+7. It can be shown that the answer can be expressed as an irreducible fraction qp, where p and q are integers and q≡0(modM). Output the integer equal to p⋅q−1modM. In other words, output such an integer x that 0≤x<M and x⋅q≡p(modM).
对每个测试用例,在一行中输出 n 个整数,其中第 i 个整数表示长度为 i 的数组的期望得分,结果对 109+7 取模。
形式化地,令 M=109+7。可以证明答案可表示为一个既约分数 qp,其中 p 和 q 为整数,且 q≡0(modM)。请输出满足 p⋅q−1modM 的整数。换言之,输出满足 0≤x<M 且 x⋅q≡p(modM) 的整数 x。
输入输出样例
输入#1
4 2 1 2 1 2 1 2 3 3 1 3 1 4 5 5 1 1 1 1 3 2 5 4 6 0 2 4 3 2 1 5 5 6 5 7 1 6 1 3 4 7 9 0 4 5 2 4
输出#1
500000005 750000007 1 1 1 200000005 333333339 333333339 500000005 880952391 801587311 781746041 789304620
说明/提示
In the first test case, if we choose k=1, there are 2 possible arrays with equal probabilities: [1] and [−1]. The S values for them are 1 and 0. So the expected score is 21h0+21h1=23. If we choose k=2, there are 4 possible arrays with equal probabilities: [1,1], [1,−1], [−1,1], [−1,−1], and the S values for them are 2,1,0,0. So the expected score is 21h0+41h1+41h2=47.
In the second test case, no matter what the S value is, the score is always 1, so the expected score is always 1.
在第一个测试用例中,若选择 k=1,则存在 2 种等概率的可能数组:[1] 和 [−1],它们对应的 S 值分别为 1 和 0。因此期望得分为 21h0+21h1=23。若选择 k=2,则存在 4 种等概率的可能数组:[1,1]、[1,−1]、[−1,1]、[−1,−1],它们对应的 S 值分别为 2,1,0,0。因此期望得分为 21h0+41h1+41h2=47。
在第二个测试用例中,无论 S 取何值,得分恒为 1,因此期望得分恒为 1。
输入解题思路,AI测评打分。不知道怎么写?