有 n n n个随机变量 x i x_i xi,取值为 [ l i , r i ] [l_i,r_i] [li,ri]中的实数。问 ∣ x 1 + ⋯ + x n ∣ |x_1+\dots+x_n| ∣x1+⋯+xn∣的期望。
n ≤ 15 , − 1 0 6 ≤ l i , r i ≤ 1 0 6 n\le15,-10^6\le l_i,r_i\le 10^6 n≤15,−106≤li,ri≤106
相当于要求 1 ∏ i = 1 n r i − l i ∫ l 1 r 1 ​ ⋯ ∫ l n r n ∣ x 1 + ⋯ + x n ∣   d x n … d x 1 \frac{1}{\prod_{i=1}^nr_i-l_i}\int_{l_1}^{r_1}\dots\int_{l_n}^{r_n}|x_1+\dots+x_n|\,dx_n\dots dx_1 ∏i=1nri−li1∫l1r1⋯∫lnrn∣x1+⋯+xn∣dxn…dx1
显然有 ∣ x ∣ = m a x ( x , 0 ) − m i n ( x , 0 ) |x|=max(x,0)-min(x,0) ∣x∣=max(x,0)−min(x,0),设 S i = ∑ j = 1 n x j S_i=\sum_{j=1}^nx_j Si=∑j=1nxj,考虑求 ∫ l 1 r 1 ​ ⋯ ∫ l n r n m a x ( S n , 0 )   d S n … d S 1 \int_{l_1}^{r_1}\dots\int_{l_n}^{r_n}max(S_n,0)\,dS_n\dots dS_1 ∫l1r1⋯∫lnrnmax(Sn,0)dSn…dS1
这里要满足 S i − S i − 1 ∈ [ l i , r i ] S_i-S_{i-1}\in [l_i,r_i] Si−Si−1∈[li,ri]
对于 m i n ( S n , 0 ) min(S_n,0) min(Sn,0)则同理。
设 k = ∑ i = 1 n r i k=\sum_{i=1}^nr_i k=∑i=1nri,通过容斥消掉范围的限制,因为这里求的是期望,也就是积分式是一次的,所以可以直接提一个常数出来然后改变积分的上下界,那么每个 x i x_i xi的取值就为 [ − ∞ , 0 ] [-\infin,0] [−∞,0].
如果 k ≤ 0 k\le 0 k≤0贡献为 0 0 0,否则贡献为 ∫ − k 0 ​ ⋯ ∫ − k 0 S n + k   d S n … d S 1 \int_{-k}^{0}\dots\int_{-k}^{0}S_n+k\,dS_n\dots dS_1 ∫−k0⋯∫−k0Sn+kdSn…dS1
这里需要满足 0 ≥ S 1 ≥ ⋯ ≥ S n ≥ − k 0\ge S_1\ge\dots\ge S_n\ge -k 0≥S1≥⋯≥Sn≥−k
= ∫ 0 k ​ ⋯ ∫ 0 k S n ′   d S n ′ … d S 1 ′ =\int_{0}^{k}\dots\int_{0}^{k}S'_n\,dS'_n\dots dS'_1 =∫0k⋯∫0kSn′dSn′…dS1′
这里要满足 0 ≤ S 1 ′ ≤ ⋯ ≤ S n ′ ≤ k 0\le S'_1\le\dots\le S'_n\le k 0≤S1′≤⋯≤Sn′≤k,设 S n + 1 ′ = S ′ n S_{n+1}'=S'n Sn+1′=S′n,则 = ∫ 0 k ​ ⋯ ∫ 0 k 1   d S n + 1 ′   d S n ′ … d S 1 ′ =\int_{0}^{k}\dots\int_{0}^{k}1\,dS'_{n+1}\,dS_n'\dots dS_1' =∫0k⋯∫0k1dSn+1′dSn′…dS1′
由于这里的 S i ′ S_i' Si′要满足一个偏序关系,所以求出来的答案要除以一个 ( n + 1 ) ! (n+1)! (n+1)!
= k n + 1 ( n + 1 ) ! =\frac{k^{n+1}}{(n+1)!} =(n+1)!kn+1
时间复杂度 O ( 2 n ) O(2^n) O(2n)
#include
#include
#include
#include
#include
typedef long long LL;
const int N=20;
const int MOD=998244353;
int n,l[N],r[N],c,ans;
int ksm(int x,int y)
{
int ans=1;
while (y)
{
if (y&1) ans=(LL)ans*x%MOD;
x=(LL)x*x%MOD;y>>=1;
}
return ans;
}
void dfs1(int x,int k,int f)
{
if (x>n) {if (k>=0) (ans+=f*ksm(k,n+1))%=MOD;return;}
dfs1(x+1,k,f);
dfs1(x+1,k-(r[x]-l[x]),-f);
}
void dfs2(int x,int k,int f)
{
if (x>n) {if (k<=0) (ans+=f*ksm(-k,n+1))%=MOD;return;}
dfs2(x+1,k,f);
dfs2(x+1,k+(r[x]-l[x]),-f);
}
int main()
{
scanf("%d",&n);
c=1;
for (int i=2;i<=n+1;i++) c=(LL)c*i%MOD;
for (int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]),c=(LL)c*(r[i]-l[i])%MOD;
c=ksm(c,MOD-2);
int s=0;
for (int i=1;i<=n;i++) s+=r[i];
dfs1(1,s,1);
s=0;
for (int i=1;i<=n;i++) s+=l[i];
dfs2(1,s,1);
ans=(LL)ans*c%MOD;
printf("%d\n",(ans+MOD)%MOD);
return 0;
}