Let MEX(S,k) be the k-th positive integer in ascending order that is not present in S.
Denote MEOW(a) as the sum of MEX(b,∣b∣+1) over all distinct subsets b of array a.
Given an array a of length n, consisting of 1,2,…,n. Determine the value of MEOW(a).
1≤n≤5000.
Consider a subset b of array a. Assume that the maximum value in b is m, and there are exactly x numbers <m that are not present in b. We have
m−x=∣b∣MEX(b,∣b∣+1)=MEX(b,m−x+1)
For convenience, let T=MEX(b,m−x+1). We now distinguish between two cases.
If ∣b∣+1=m−x+1>x, i.e. m≥2x, then T>m holds, which implies that
T=m+∣b∣+1−x=2m−2x+1
Thus, for fixed m and x, their contribution to the final answer is
(2m−2x+1)(xm−1)
Otherwise, m<2x, and T<m holds.
Since T is undetermined, we can simply enumerate all possible values of T from 1 to m−1.
Consider the current T, which is the (m−x+1)-th integer that is not present. Hence, there are m−x integers ∈[1,T) and 2x−m−1 integers ∈(T,m) which are not present.
Thus, for fixed m and x, their contribution to the final answer is