CF1783D.Different Arrays
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integers.
You have to perform the sequence of n−2 operations on this array:
- during the first operation, you either add a2 to a1 and subtract a2 from a3, or add a2 to a3 and subtract a2 from a1;
- during the second operation, you either add a3 to a2 and subtract a3 from a4, or add a3 to a4 and subtract a3 from a2;
- ...
- during the last operation, you either add an−1 to an−2 and subtract an−1 from an, or add an−1 to an and subtract an−1 from an−2.
So, during the i-th operation, you add the value of ai+1 to one of its neighbors, and subtract it from the other neighbor.
For example, if you have the array [1,2,3,4,5], one of the possible sequences of operations is:
- subtract 2 from a3 and add it to a1, so the array becomes [3,2,1,4,5];
- subtract 1 from a2 and add it to a4, so the array becomes [3,1,1,5,5];
- subtract 5 from a3 and add it to a5, so the array becomes [3,1,−4,5,10].
So, the resulting array is [3,1,−4,5,10].
An array is reachable if it can be obtained by performing the aforementioned sequence of operations on a. You have to calculate the number of reachable arrays, and print it modulo 998244353.
给你一个包含 n 个整数的数组 a。
你需要对该数组执行 n−2 次操作,操作顺序如下:
- 在第一次操作中,你或者将 a2 加到 a1 上、同时从 a3 中减去 a2,或者将 a2 加到 a3 上、同时从 a1 中减去 a2;
- 在第二次操作中,你或者将 a3 加到 a2 上、同时从 a4 中减去 a3,或者将 a3 加到 a4 上、同时从 a2 中减去 a3;
- …
- 在最后一次操作中,你或者将 an−1 加到 an−2 上、同时从 an 中减去 an−1,或者将 an−1 加到 an 上、同时从 an−2 中减去 an−1。
换言之,在第 i 次操作中,你将 ai+1 的值加到其一个相邻元素上,并从其另一个相邻元素中减去该值。
例如,若初始数组为 [1,2,3,4,5],一种可能的操作序列如下:
- 从 a3 中减去 2,并加到 a1 上,数组变为 [3,2,1,4,5];
- 从 a2 中减去 1,并加到 a4 上,数组变为 [3,1,1,5,5];
- 从 a3 中减去 5,并加到 a5 上,数组变为 [3,1,−4,5,10]。
最终得到的数组为 [3,1,−4,5,10]。
若某个数组可通过上述操作序列由 a 得到,则称其为可达数组。你需要计算可达数组的总数,并对 998244353 取模后输出结果。
输入格式
The first line contains one integer n (3≤n≤300).
The second line contains n integers a1,a2,…,an (0≤ai≤300).
第一行包含一个整数 n(3≤n≤300)。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤300)。
输出格式
Print one integer — the number of reachable arrays. Since the answer can be very large, print its remainder modulo 998244353.
输出一个整数——可达数组的个数。由于答案可能非常大,请输出其对 998244353 取模的结果。
输入输出样例
输入#1
4 1 1 1 1
输出#1
3
输入#2
5 1 2 3 5 0
输出#2
7
输入解题思路,AI测评打分。不知道怎么写?