004. Multiplying Adjacent Elements in a Permutation

Given a permutation (a1,a2,,an)(a_1, a_2, \cdots, a_n) of {1,2,,n}\{ 1, 2, \cdots, n \}, maximize a1a2+a2a3++an1an+ana1a_1 a_2 + a_2 a_3 + \cdots + a_{n-1} a_n + a_n a_1.


Let Mn=max(a1a2+a2a3++an1an+ana1)M_n = \max (a_1 a_2 + a_2 a_3 + \cdots + a_{n-1} a_n + a_n a_1). Note that MnM_n of a permutation is always the same as the ones of its cyclic permutations. Observe the amount of change updating {1,2,,n1}\{ 1, 2, \cdots, n - 1 \} to {1,2,,n}\{ 1, 2, \cdots, n \}. When nn is inserted between aka_k and ak+1a_{k + 1}, the amount of change is nak+nak+1akak+1=nak+nak+1akak+1+n2n2=n2{n2n(ak+ak+1)+akak+1}=n2(nak)(nak+1)n2{n(n1)}{n(n2)}=n22\begin{aligned} n a_k + n a_{k + 1} - a_k a_{k + 1} &= n a_k + n a_{k + 1} - a_k a_{k + 1} + n^2 - n^2 \\ &= n^2 - \{ n^2 - n (a_k + a_{k + 1}) + a_k a_{k + 1} \} \\ &= n^2 - (n - a_k) (n - a_{k + 1}) \\ &\leq n^2 - \{n - (n - 1)\} \{n - (n - 2)\} = n^2 - 2 \end{aligned}

where 1kn11 \leq k \leq n - 1. Although k+1k + 1 must be 11 when k=n1k = n - 1, the above inequality is always valid since the permutation can be cyclic keeping Mn1M_{n - 1}. So, the maximum amount of change is n22n^2 - 2, which means MnMn1=n22M_n - M_{n - 1} = n^2 - 2. Also, this only happens when nn is inserted between n1n - 1 and n2n - 2 in a situation where n1n - 1 and n2n - 2 are adjacent. From M2=a1a2+a2a1=4M_2 = a_1 a_2 + a_2 a_1 = 4, M3=M2+322M4=M3+422Mn=Mn1+n22    Mn=M2+(322)+(422)++(n22)=4+(12+22++n2)(12+22)2(n2)=(12+22++n2)2n+3=n(n+1)(2n+1)62n+3(n2)\begin{aligned} M_3 &= M_2 + 3^2 - 2 \\ M_4 &= M_3 + 4^2 - 2 \\ &\qquad \vdots \\ M_n &= M_{n - 1} + n^2 - 2 \\\\ \implies M_n &= M_2 + (3^2 - 2) + (4^2 - 2) + \cdots + (n^2 - 2) \\ &= 4 + (1^2 + 2^2 + \cdots + n^2) - (1^2 + 2^2) - 2(n - 2) \\ &= (1^2 + 2^2 + \cdots + n^2) -2n + 3 \\ &= \frac{n(n + 1)(2n + 1)}{6} - 2n + 3 \qquad (n \geq 2) \end{aligned}

Enumerating MnM_n starting from n=3n = 3, M31,3,2M41,3,4,2M51,3,5,4,2Mn={1,3,,n3,n1,n,n2,,4,2(n is even)1,3,,n2,n,n1,n3,,4,2(n is odd)\begin{aligned} M_3 &\Longleftarrow 1, 3, 2 \\ M_4 &\Longleftarrow 1, 3, 4, 2 \\ M_5 &\Longleftarrow 1, 3, 5, 4, 2 \\ &\qquad \vdots \\ M_n &= \begin{cases} 1, 3, \cdots, n - 3, n - 1, n, n - 2, \cdots, 4, 2 \qquad (n \text{ is even}) \\\\ 1, 3, \cdots, n - 2, n, n - 1, n - 3, \cdots, 4, 2 \qquad (n \text{ is odd}) \end{cases} \end{aligned}


© 2024. All rights reserved.