CF2200G.Operation Permutation
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
AksLolCoding has an integer x and a list of n operations. Each operation is a string starting with one of the symbols +,-,x, or / (representing addition, subtraction, multiplication, and real number division respectively), followed immediately by a positive integer y (1≤y≤109). For example, the operation x3 represents multiplying x by 3.
AksLolCoding will randomly permute the operations and then apply all operations sequentially to x in the permuted order. Help AksLolCoding compute the expected∗ final value of x 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−1(modM). In other words, output such an integer a that 0≤a<M and a⋅q≡p(modM).
∗The expected final value of x is the average of the final value of x over all n! permutations.
AksLolCoding 有一个整数 x 和一个包含 n 个操作的列表。每个操作是一个字符串,以符号 +、-、x 或 /(分别表示加法、减法、乘法和实数除法)之一开头,其后紧跟着一个正整数 y(1≤y≤109)。例如,操作 x3 表示将 x 乘以 3。
AksLolCoding 将随机打乱这些操作的顺序,然后按打乱后的顺序依次对 x 执行所有操作。请帮助 AksLolCoding 计算 x 的最终值的期望值(对所有 n! 种排列取平均)模 109+7 的结果。
形式化地,令 M=109+7。可以证明答案可表示为最简分数 qp,其中 p 和 q 为整数,且 q≡0(modM)。请输出满足 p⋅q−1(modM) 的整数。换言之,输出满足 0≤a<M 且 a⋅q≡p(modM) 的整数 a。
∗ x 的最终值的期望值,即对全部 n! 种排列所得最终值取算术平均。
输入格式
The first line contains a single integer t (1≤t≤1000), the number of test cases.
For each test case, the first line contains two integers n and x (1≤n≤3000, 1≤x≤109).
The second line of each test case contains n strings, each representing an operation in the format described above.
The sum of n2 over all test cases does not exceed 30002.
Note: x is used to represent multiplication, not *
第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。
对于每个测试用例,第一行包含两个整数 n 和 x(1≤n≤3000,1≤x≤109)。
每个测试用例的第二行包含 n 个字符串,每个字符串表示一个如上所述格式的操作。
所有测试用例中 n2 的总和不超过 30002。
注意:此处的 x 表示乘法运算,而非 \*。
输出格式
For each test case, output a single integer: the expected final value of x modulo 109+7.
对于每个测试用例,输出一个整数:x 的最终期望值对 109+7 取模的结果。
输入输出样例
输入#1
4 2 10 x2 -10 4 2 +6 +7 /1 -13 8 1 +1 x2 x3 +4 +5 +6 -7 -8 9 864209753 -918273645 x564738291 /365107362 x734582911 -654321789 x998244353 +172519103 /482193765 /482091376
输出#1
5 2 166666677 601980218
说明/提示
In the first test case, x can either be (10⋅2)−10=10 or (10−10)⋅2=0, resulting in an expected value of 5.
In the second test case, all possible permutations result in x=2.
In the third test case, the expected value of x is 655.
在第一个测试用例中,x 的值可以是 (10⋅2)−10=10 或 (10−10)⋅2=0,因此期望值为 5。
在第二个测试用例中,所有可能的排列均得到 x=2。
在第三个测试用例中,x 的期望值为 655。
输入解题思路,AI测评打分。不知道怎么写?