[NowCoder5666D]Quadratic Form

题意

max ⁡ x b T x s . t . x T A x − 1 ≤ 0 \begin{aligned} \max_x &\quad b^Tx\\ {\rm s.t.} &\quad x^TAx-1\le0 \end{aligned} xmaxs.t.bTxxTAx10
( b T x ) 2 m o d    998244353 (b^Tx)^2\mod 998244353 (bTx)2mod998244353.

A A A n × n n\times n n×n对称矩阵, b , x ∈ R n b,x\in\mathbb{R}^n b,xRn
n ≤ 200 , 0 ≤ ∣ A i , j ∣ , ∣ b i ∣ ≤ 1 0 9 n\le200,0\le|A_{i,j}|,|b_i|\le10^9 n200,0Ai,j,bi109
∀ x ∈ R n /   { 0 } , x T A x > 0 \forall x\in\mathbb{R}^n/\ \{\boldsymbol0\},x^TAx>0 xRn/ {0},xTAx>0
det ⁡ ( A ) ≢ 0 ( m o d 998244353 ) \det(A)\not\equiv0\pmod{998244353} det(A)0(mod998244353)


题解

设兰格朗日函数 L ( x , λ ) = b T x + λ ( x T A x − 1 ) \mathcal{L}(x,\lambda)=b^Tx+\lambda(x^TAx-1) L(x,λ)=bTx+λ(xTAx1),根据向量求导法则,有
∂ L ∂ x = b + λ ( A + A T ) x = b + 2 λ A x \frac{\partial\mathcal{L}}{\partial x}=b+\lambda(A+A^T)x=b+2\lambda Ax xL=b+λ(A+AT)x=b+2λAx
∂ L ∂ x = 0 \displaystyle\frac{\partial\mathcal{L}}{\partial x}=0 xL=0,可得 x = − A − 1 b 2 λ \displaystyle x=-\frac{A^{-1}b}{2\lambda} x=2λA1b。由KKT条件: λ ( x T A x − 1 ) = 0 , λ ≤ 0 \lambda(x^TAx-1)=0,\lambda\le0 λ(xTAx1)=0,λ0。将 x x x带入得
λ [ ( − A − 1 b 2 λ ) T A ( − A − 1 b 2 λ ) − 1 ] = 0 ⇒ b T ( A − 1 ) T A A − 1 b = 4 λ 2 , ( A − 1 ) T = A − 1 ⇒ λ = − 1 2 b T A − 1 b \begin{aligned} &\lambda[(-\frac{A^{-1}b}{2\lambda})^TA(-\frac{A^{-1}b}{2\lambda})-1]=0\\ \Rightarrow&\qquad b^T(A^{-1})^TAA^{-1}b=4\lambda^2,\quad (A^{-1})^T=A^{-1}\\ \Rightarrow&\qquad \lambda=-\frac12\sqrt{b^TA^{-1}b} \end{aligned} λ[(2λA1b)TA(2λA1b)1]=0bT(A1)TAA1b=4λ2,(A1)T=A1λ=21bTA1b

b T x = b T ( − A − 1 b 2 λ ) = − b T A − 1 b b T A − 1 b = b T A − 1 b b^Tx=b^T(-\frac{A^{-1}b}{2\lambda})=-\frac{b^TA^{-1}b}{\sqrt{b^TA^{-1}b}}=\sqrt{b^TA^{-1}b} bTx=bT(2λA1b)=bTA1b bTA1b=bTA1b
最终的答案为 ( b T x ) 2 = b T A − 1 b (b^Tx)^2=b^TA^{-1}b (bTx)2=bTA1b。用高斯消元求出 A A A的逆再相乘即可。

单组数据时间复杂度 O ( n 3 ) O(n^3) O(n3)

你可能感兴趣的:(高斯消元,拉格朗日乘数法)