CF2159C.Twin Polynomials
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A polynomial f(x)=a0+a1x+a2x2+…+anxn is called a valid polynomial of degree n if and only if ai is a non-negative integer for all 0≤i≤n and an is not 0.
For a valid polynomial f(x)=a0+a1x+a2x2+…+anxn of degree n, its twin polynomial g(x) is defined as: $$ g(x) = \sum_{i=0}^n i \cdot x^{a_i} $$ For example, for f(x)=1+2x+2x3, its twin polynomial is:
g(x)=0cdotx1+1cdotx2+2cdotx0+3cdotx2=0+x2+2+3x2=2+4x2
A valid polynomial f(x) of degree n is called cool if and only if f(x)=g(x). In other words, a valid polynomial of degree n is cool if and only if its twin polynomial equals itself.
You are given an incomplete valid polynomial f(x)=a0+a1x+a2x2+…+anxn of degree n. Some of ai have been determined, while others have not been determined. Additionally, it is guaranteed that a0 and an are not determined.
Please count the number of cool valid polynomials of degree n that can be found by determining all undetermined ai's. Since the answer may be large, you need to output it modulo 1000000007.
一个多项式 f(x)=a0+a1x+a2x2+…+anxn 被称为合法的 n 次多项式,当且仅当对所有 0≤i≤n,系数 ai 均为非负整数,且首项系数 an=0。
对于一个合法的 n 次多项式 f(x)=a0+a1x+a2x2+…+anxn,其孪生多项式 g(x) 定义为:
g(x)=i=0∑ni⋅xai
例如,对 f(x)=1+2x+2x3,其孪生多项式为:
g(x)=0⋅x1+1⋅x2+2⋅x0+3⋅x2=0+x2+2+3x2=2+4x2
一个合法的 n 次多项式 f(x) 被称为酷多项式(cool polynomial),当且仅当 f(x)=g(x)。换言之,一个合法的 n 次多项式是酷多项式,当且仅当它的孪生多项式等于它自身。
现给出一个不完整的合法 n 次多项式 f(x)=a0+a1x+a2x2+…+anxn,其中部分系数 ai 已确定,其余未确定。此外,保证 a0 和 an 均未确定。
请计算:通过为所有未确定的 ai 赋值,能够得到多少个酷的合法 n 次多项式。由于答案可能很大,请输出其对 1000000007 取模的结果。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
For each test case, the first line contains an integer n (1≤n≤4⋅105).
The second line contains n+1 integers a0,a1,…,an (−1≤ai≤109). Here, ai=−1 means ai has not been determined, while ai=−1 means ai has been determined as its value.
It is guaranteed that a0 and an are always −1 in the input.
It is guaranteed that the sum of n over all test cases does not exceed 4⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
对于每个测试用例,第一行包含一个整数 n(1≤n≤4⋅105)。
第二行包含 n+1 个整数 a0,a1,…,an(−1≤ai≤109)。其中,ai=−1 表示 ai 尚未确定;而 ai=−1 表示 ai 已被确定为其给定值。
保证输入中 a0 和 an 恒为 −1。
保证所有测试用例的 n 值之和不超过 4⋅105。
输出格式
For each test case, output the number of cool valid polynomials of degree n found by determining the undetermined ai's, modulo 1000000007.
对于每个测试用例,输出通过确定未定系数 ai 所找到的次数为 n 的“酷”有效多项式的数量,结果对 1000000007 取模。
输入输出样例
输入#1
6 1 -1 -1 2 -1 2 -1 2 -1 -1 -1 3 -1 -1 3 -1 3 -1 2 3 -1 5 -1 -1 -1 1 0 -1
输出#1
1 1 3 2 0 3
说明/提示
In the first test case, only f(x)=x satisfies the condition above.
In the second test case, only f(x)=x2+2x satisfies the condition above.
In the third test case, f(x)=2x2+x, f(x)=x2+2x, and f(x)=2x2+1 satisfy the condition above.
在第一个测试用例中,只有 f(x)=x 满足上述条件。
在第二个测试用例中,只有 f(x)=x2+2x 满足上述条件。
在第三个测试用例中,f(x)=2x2+x、f(x)=x2+2x 和 f(x)=2x2+1 满足上述条件。
输入解题思路,AI测评打分。不知道怎么写?