传送门:luoguP4707
exMin-Max容斥
max
k
(
S
)
=
∑
T
⊆
S
(
−
1
)
∣
T
∣
+
1
(
∣
T
−
1
∣
k
−
1
)
min
(
T
)
\max\limits_k(S)=\sum\limits_{T\subseteq S}(-1)^{|T|+1}{|T-1|\choose k-1}\min(T)
kmax(S)=T⊆S∑(−1)∣T∣+1(k−1∣T−1∣)min(T)
同样的,
e
x
M
i
n
−
M
a
x
exMin-Max
exMin−Max容斥也在期望下成立,即:
E
(
max
k
(
S
)
)
=
∑
T
⊆
S
(
−
1
)
∣
T
∣
+
1
(
∣
T
−
1
∣
k
−
1
)
E
(
min
(
T
)
)
E(\max\limits_k(S))=\sum\limits_{T\subseteq S}(-1)^{|T|+1}{|T-1|\choose k-1}E(\min(T))
E(kmax(S))=T⊆S∑(−1)∣T∣+1(k−1∣T−1∣)E(min(T))
(证明略)
题解
k → n − k + 1 k\to n-k+1 k→n−k+1后套用 e x M i n − M a x exMin-Max exMin−Max容斥 E ( max k ( S ) ) = ∑ T ⊆ S ( − 1 ) ∣ T ∣ + 1 ( ∣ T − 1 ∣ k − 1 ) E ( min ( T ) ) E(\max\limits_k(S))=\sum\limits_{T\subseteq S}(-1)^{|T|+1}{|T-1|\choose k-1}E(\min(T)) E(kmax(S))=T⊆S∑(−1)∣T∣+1(k−1∣T−1∣)E(min(T))
E ( min ( T ) ) = m ∑ t ∈ T p t E(\min(T))=\dfrac{m}{\sum\limits_{t\in T}p_t} E(min(T))=t∈T∑ptm
观察到 n , m , k n,m,k n,m,k都很小,考虑 d p [ k ] [ i ] [ j ] dp[k][i][j] dp[k][i][j]表示确定式子中 k k k的值,前 i i i个材料中任意一个满足 ( ∑ t ∈ T p t ) = j (\sum \limits_{t\in T}p_t)=j (t∈T∑pt)=j的集合 T T T的 ( − 1 ) ∣ T ∣ − k ( ∣ T ∣ − 1 k − 1 ) (-1)^{|T|-k}{|T|-1\choose k-1} (−1)∣T∣−k(k−1∣T∣−1)之和,即 ∑ T , m a x ( T ) ≤ i [ ( ∑ t ∈ T p t ) = j ] ( − 1 ) ∣ T ∣ − k ( ∣ T ∣ − 1 k − 1 ) \sum\limits_{T,max(T)\leq i}[(\sum \limits_{t\in T}p_t)=j](-1)^{|T|-k}{|T|-1\choose k-1} T,max(T)≤i∑[(t∈T∑pt)=j](−1)∣T∣−k(k−1∣T∣−1)。
由 ( ∣ T ∣ − 1 k − 1 ) = ( ∣ T ∣ − 2 k − 1 ) + ( ∣ T ∣ − 2 k − 2 ) {|T|-1\choose k-1}={|T|-2\choose k-1}+{|T|-2\choose k-2} (k−1∣T∣−1)=(k−1∣T∣−2)+(k−2∣T∣−2)得到递推式:
d p [ k ] [ i ] [ j ] = d p [ k ] [ i − 1 ] [ j ] + d p [ k − 1 ] [ i − 1 ] [ j − p i ] − d p [ k ] [ i − 1 ] [ j − p i ] dp[k][i][j]=dp[k][i-1][j]+dp[k-1][i-1][j-p_i]-dp[k][i-1][j-p_i] dp[k][i][j]=dp[k][i−1][j]+dp[k−1][i−1][j−pi]−dp[k][i−1][j−pi]
注意初始化 d p [ 0 ] [ 0 ] [ 0 ] = 0 , d p [ k ] [ 0 ] [ 0 ] = − 1 ( k > 0 ) dp[0][0][0]=0,dp[k][0][0]=-1(k>0) dp[0][0][0]=0,dp[k][0][0]=−1(k>0),以保证 ∣ T ∣ = k |T|=k ∣T∣=k的贡献为 1 1 1, ∣ T ∣ < k |T|<k ∣T∣<k的贡献为 0 0 0。(玄学初始化,雾)
答案即为 m ∑ i = 1 m d p [ n ] [ k ] [ i ] i m o d    998244353 m\sum\limits_{i=1}^m\dfrac{dp[n][k][i]}{i} \mod 998244353 mi=1∑midp[n][k][i]mod998244353
代码
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef long long ll;
int n,K,m,p[1005],f[2][12][10005],ans,nv[10005];
inline void ad(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void dc(int &x,int y){x-=y;if(x<0) x+=mod;}
int main(){
int i,j,k,pr=0,v;
scanf("%d%d%d",&n,&K,&m);K=n-K+1;
for(i=1;i<=n;++i) scanf("%d",&p[i]);
for(i=1;i<=K;++i) f[0][i][0]=mod-1;
for(i=1;i<=n;++i){
v=p[i];pr^=1;memcpy(f[pr],f[pr^1],sizeof(f[pr]));
for(j=0;j<=K;++j)
for(k=v;k<=m;++k){
dc(f[pr][j][k],f[pr^1][j][k-v]);
if(j) ad(f[pr][j][k],f[pr^1][j-1][k-v]);
}
}
nv[0]=nv[1]=1;
for(i=1;i<=m;){
ad(ans,(ll)f[pr][K][i]*nv[i]%mod);i++;
nv[i]=(ll)(mod-mod/i)*nv[mod%i]%mod;
}
printf("%d",(ll)ans*m%mod);
return 0;
}