464 Let non-negative real numbers $x_{1}, x_{2}, \cdots, x_{n}$ satisfy $\sum_{i=1}^{n} x_{i}=n$. Find the maximum value of $\sum_{k=1}^{n-1} x_{k} x_{k+1}+x_{1}+x_{n}$.
(1) When $n$ is odd,
$$
\begin{array}{l}
\sum_{k=1}^{n-1} x_{k} x_{k+1}+x_{1}+x_{n} \\
\leqslant\left(x_{1}+x_{3}+\cdots+x_{n}\right)\left(x_{2}+x_{4}+\cdots+x_{n-1}\right)+\left(x_{1}\right. \\
\leqslant\left(x_{1}+x_{3}+\cdots+x_{n}\right)\left(x_{2}+x_{4}+\cdots+x_{n-1}\right. \\
\leqslant\left(\frac{n+1}{2}\right)^{2} .
\end{array}
$$

When $x_{1}=\frac{n+1}{2}, x_{2}=\frac{n-1}{2}, x_{3}=x_{4}=\cdots=x$, the equality holds.
(2) When $n$ is even,
$$
\begin{array}{l}
\text { If } x_{n} \leqslant x_{3}+x_{5}+\cdots+x_{n-1} \text {, then } \\
\sum_{k=1}^{n-1} x_{k} x_{k+1}+x_{1}+x_{n} \\
\leqslant\left(x_{1}+x_{3}+\cdots+x_{n-1}\right)\left(x_{2}+x_{4}+\cdots+x_{n}\right. \\
\leqslant\left(\frac{n+1}{2}\right)^{2} ;
\end{array}
$$

If $x_{1} \leqslant x_{2}+x_{4}+\cdots+x_{n-2}$, then
$$
\begin{array}{l}
\sum_{k=1}^{n-1} x_{k} x_{k+1}+x_{1}+x_{n} \\
\leqslant\left(x_{1}+x_{3}+\cdots+x_{n-1}+1\right)\left(x_{2}+x_{4}+\cdots+\right. \\
\leqslant\left(\frac{n+1}{2}\right)^{2}
\end{array}
$$

If $x_{n}>x_{3}+x_{5}+\cdots+x_{n-1}$,
$$
x_{1}>x_{2}+x_{4}+\cdots+x_{n-2} \text {, }
$$

Assume $x_{1} \geqslant x_{n}$, then
$$
\begin{array}{l}
\sum_{k=1}^{n-1} x_{k} x_{k+1}+x_{1}+x_{n} \\
\leqslant x_{1}\left(x_{2}+x_{3}+\cdots+x_{n-1}\right)+x_{1}+x_{n} \\
\leqslant\left(x_{1}+x_{n}\right)\left(x_{2}+x_{3}+\cdots+x_{n-1}+1\right) \\
\leqslant\left(\frac{n+1}{2}\right)^{2}
\end{array}
$$