Is there any better than a brute force method for finding the maximum
$$\max\limits\_{ (d\_{1},\dots,d\_{n}) \in \mathbb Z\_{m}^{n}} \sum\_{j=0}^{m-1} \left(\sum\_{i=1}^{n}v\_{i,(j+d\_{i})\bmod m}\right)^{2}$$
for $m,n \in \mathbb N^{+}$ and $v\_{i,j} \in \mathbb Z$?



How to find the maximum of a sum of squares of sums?
You can solve the problem via binary quadratic programming as follows. Let binary decision variable $x\_{id}$ indicate whether row $i$ is rotated $d$ places. The problem is to maximize
$$\sum\_{j=0}^{m-1} \left(\sum\_{i=1}^n \sum\_{d=0}^{m-1} v\_{i,(j+d) \bmod m} x\_{id} \right)^2$$
subject to
$$\sum\_{d=0}^{m-1} x\_{id} = 1 \quad \text{for $i \in \{1,\dots,n\}$}.$$


You can either call an MIQP solver or linearize the products of binary variables and call an MILP solver.


