Problem Statement
题目简述:
n 个格子围成一个圆,编号 0 到 n-1。
用 p[i] 表示 i 号格子上的数,p[i] 是非负整数。
这个圆圈关于 0 号位置对称,即 p[i mod n] = p[(-i) mod n]。
现在给出将 p 数组做一次循环卷积后的数组 a,
求可能的 p 数组中字典序最小的。如果没有,返回 -1。
数据范围:n <= 25, 0 <= a_i <= 10^6。
Once again, Fox Ciel is practicing splitting.
This time there are N cells arranged into a circle.
The cells are numbered 0 through N-1 around the circle (with cell N-1 being adjacent to cell 0).
At the beginning, there was exactly 1 fox in cell 0, and all the remaining cells were empty.
Then there were two rounds of splitting, as described below.
There is some unknown splitting pattern P: a sequence of N non-negative integers.
The pattern should also be considered cyclic: P[N-1] is adjacent to P[0].
The pattern is known to be symmetric around 0.
Formally, for each i, P[i mod N] = P[(-i) mod N].
For example, for N=5 one valid pattern is P=(3,1,4,4,1).
Note that for N=5 we must have P[1]=P[4] and P[2]=P[3].
We will now describe what happens when a fox splits.
Assume that the fox is currently in the cell x.
The fox that splits disappears.
In its place, new foxes appear according to the pattern P.
For each i from 0 to N-1, inclusive, P[i] new foxes appear in the cell (x+i) mod N.
In each round of splitting, all of the currently present foxes split at the same time, independent from each other.
All the foxes use the same splitting pattern P.
You are given a int[] amount with N elements.
For each i, amount[i] is the number of foxes in cell i after the second round of splitting.
Your goal is to recover and return the pattern P.
If there are multiple possibilities, return the lexicographically smallest one.
If there is no pattern P that can produce amount, return {-1}.
(I.e., the return value should be a int[] with 1 element, and the value of the element should be -1.)