$$ \begin{bmatrix} x_1 \ x_2 \ x_3 \ x_4 \end{bmatrix} = \underbrace{\begin{bmatrix} 1 & 0 & 0 & 0 \ 1 & 1 & 0 & 0 \ 1 & 1 & 1 & 0 \ 1 & 1 & 1 & 1 \end{bmatrix}}_{=: {\bf L}} \begin{bmatrix} u_0 \ u_1 \ u_2 \ u_3 \end{bmatrix} + x_0\begin{bmatrix} 1 \ 1 \ 1 \ 1 \end{bmatrix} $$
or, more succinctly,
$$ {\bf x} = {\bf L} {\bf u} + x_0 {\bf 1}_4 $$
Since the final state cost is zero, we define weight vector ${\bf w} := \begin{bmatrix} 1 & 1 & 1 & 0 \end{bmatrix}^\top$. Hence, the optimal control input sequence can be found via
$$\boxed{\begin{array}{ll} \underset{{\bf u} \in \Bbb Z^4}{\text{minimize}} & x_0^2 + \left\| \mbox{diag}({\bf w}) \left( {\bf L} {\bf u} + x_0 {\bf 1}_4 \right) \right\|_2^2 + \left\| {\bf u} \right\|_2^2 \ \text{subject to} & {\bf 0}_4 \leq {\bf L} {\bf u} + x_0 {\bf 1}_4 \leq x_0 {\bf 1}_4\end{array}}$$
which is an instance of integer regularized least squares.
Using Python (with NumPy and CVXPY),
```python import cvxpy as cp import numpy as np
x_0 = 5
L = np.array([( 1, 0, 0, 0), ( 1, 1, 0, 0), ( 1, 1, 1, 0), ( 1, 1, 1, 1)])
w = np.array([1, 1, 1, 0]) W = np.diag(w)
optimization variables
u = cp.Variable(4, integer=True)
build state vector
x = (L @ u) + (x_0 * np.ones(4))
build cost function
cost = cp.sum_squares(x_0) + cp.sum_squares(W @ x) + cp.sum_squares(u)
create optimization problem
prob = cp.Problem( cp.Minimize(cost), [ np.zeros(4) <= x, x <= x_0 * np.ones(4) ] )
solve optimization problem
solution = prob.solve(solver = cp.ECOS_BB)
print("Optimal input sequence: ", np.round( u.value, 2)) print("Optimal state sequence: ", np.append([x_0], x.value )) print("Minimal cost: ", np.round( cost.value, 2)) ```
which outputs the following
text Optimal input sequence: [-3. -1. 0. -0.] Optimal state sequence: [5. 490
2. 1. 1. 1.] Minimal cost: 41.0
Hence, one optimal solution is the following
$$ u_0 = -3, \qquad u_1 = -1, \qquad u_2 = u_3 = 0 $$
Note that this optimal solution is not unique. For details, please consider reading <PERSON>'s answer. 490