题目链接:洛谷
作为一只沉迷数学多年的蒟蒻OIer,在推柿子和dp之间肯定要选推柿子的!
首先假设线段长度为1,最后答案乘上$l$即可。
对于$x$这个位置,被区间覆盖的概率是$2x(1-x)$(线段端点分别在$x$的两边),不被区间覆盖的概率为$1-2x(1-x)$。
$$Ans=sum_{i=k}^n {nchoose i}int_{0}^1(2x(1-x))^i(1-2x(1-x))^{n-i}dx$$
$$=sum_{i=k}^n {nchoose i}int_{0}^1(2x(1-x))^isum_{j=0}^{n-i}(-1)^j{n-ichoose j}(2x(1-x))^jdx$$
$$=sum_{i=k}^n{nchoose i}sum_{j=0}^{n-i}(-1)^j2^{i+j}{n-ichoose j}int_0^1x^{i+j}(1-x)^{i+j}dx$$
$$F_i=int_0^1x^i(1-x)^idx$$
$$=int_0^1x^isum_{j=0}^i(-1)^j{ichoose j}x^jdx$$
$$=sum_{j=0}^i(-1)^j{ichoose j}int_0^1x^{i+j}dx$$
$$=sum_{j=0}^i(-1)^j{ichoose j}frac{1}{i+j+1}$$
预处理$F_i$之后计算,时间复杂度$O(n^2)$。

1 #include<bits/stdc++.h> 2 #define Rint register int 3 using namespace std; 4 typedef long long LL; 5 const int N = 4003, mod = 998244353; 6 int fac[N], inv[N], invfac[N], po[N]; 7 inline void init(int m){ 8 fac[0] = 1; 9 for(Rint i = 1;i <= m;i ++) fac[i] = (LL) i * fac[i - 1] % mod; 10 inv[1] = 1; 11 for(Rint i = 2;i <= m;i ++) inv[i] = (LL) (mod - mod / i) * inv[mod % i] % mod; 12 invfac[0] = 1; 13 for(Rint i = 1;i <= m;i ++) invfac[i] = (LL) invfac[i - 1] * inv[i] % mod; 14 po[0] = 1; 15 for(Rint i = 1;i <= m;i ++) po[i] = (po[i - 1] << 1) % mod; 16 } 17 inline int C(int n, int m){ 18 if(n < m || m < 0) return 0; 19 return (LL) fac[n] * invfac[n - m] % mod * invfac[m] % mod; 20 } 21 int n, k, l, ans, f[N]; 22 int main(){ 23 scanf("%d%d%d", &n, &k, &l); 24 init(n << 1 | 1); 25 for(Rint i = k;i <= n;i ++) 26 for(Rint j = 0;j <= i;j ++){ 27 int t = (LL) C(i, j) * inv[i + j + 1] % mod; 28 if(j & 1) f[i] = (f[i] + mod - t) % mod; else f[i] = (f[i] + t) % mod; 29 } 30 for(Rint i = k;i <= n;i ++){ 31 int t1 = 0; 32 for(Rint j = 0;j <= n - i;j ++){ 33 int t2 = (LL) po[i + j] * C(n - i, j) % mod * f[i + j] % mod; 34 if(j & 1) t1 = (t1 + mod - t2) % mod; else t1 = (t1 + t2) % mod; 35 } 36 ans = (ans + (LL) t1 * C(n, i) % mod) % mod; 37 } 38 printf("%d", (LL) l * ans % mod); 39 }
据说这个式子还可以用NTT优化到$O(nlog n)$?有兴趣的各位可以思考一下反正我是没兴趣了
upd(2019-10-18):
貌似有一个东西叫做Beta Function.
$$egin{aligned}Beta(x,y)&=int_0^1t^x(1-t)^ymathrm{d}t & (x,yin R_+)\ Gamma(z)&=int_0^{+infty}x^{z-1}e^{-x}mathrm{d}x & (Re(z)>0)end{aligned}$$
有一些不知道为什么的结论。
$$egin{aligned}Gamma(n)&=(n-1)! & (nin N_+) \ Beta(x,y)&=frac{Gamma(x)Gamma(y)}{Gamma(x+y)}end{aligned}$$
于是上面的$F_i$直接就做完了。稍微化化就可以用NTT来做了。