Suppose we have a sequence of integers $\{x_i\}$ and a permutation of this sequence changing its order $\{x_{j_i}\}$. We want to find a such a permutation making $\sum_i x_ix_{j_i} =C$, where C is a already given value. For example, given $x=\{1,2,3,4\}$ and $C=28$, then the permutation $\{2,1,4,3\}$ satisfies the above conditions.
If the above is not clear enough, essentially, the question is
Given a column vector $x$ of integer elements, and a constant $C$, find a permutation matrix $A$ such that $x^T A x=C$, where T denotes transpose.
$A$ is certainly not unique, so I am looking for a way to find all solutions.
I try to make $x$ into a square matrix by right multiply it by a row vector, but obviously this will certainly give a singular matrix without an inverse, so I make no progresses.