Solution
考虑一个不合法方案,它一定最后位置的逆序对数不为 (0),而且可以发现的是,存在对称方案使得最后逆序对数奇偶性不同,所以我们如果加上 ((-1))^{sigma(P)} (即逆序对数奇偶性),那么两者就会抵消掉。
所以可以枚举一个点的最后位置,用状压 dp 解决。
Code
#include <bits/stdc++.h>
using namespace std;
#define Int register int
#define mod 998244353
#define MAXN 1005
template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
template <typename T> inline void chkmax (T &a,T b){a = max (a,b);}
template <typename T> inline void chkmin (T &a,T b){a = min (a,b);}
int n,m,x[MAXN],C[MAXN],f[1 << 10];
int mul (int a,int b){return 1ll * a * b % mod;}
int dec (int a,int b){return a >= b ? a - b : a + mod - b;}
int add (int a,int b){return a + b >= mod ? a + b - mod : a + b;}
int qkpow (int a,int b){
int res = 1;for (;b;b >>= 1,a = mul (a,a)) if (b & 1) res = mul (res,a);
return res;
}
void Sub (int &a,int b){a = dec (a,b);}
void Add (int &a,int b){a = add (a,b);}
signed main(){
read (m,n),C[0] = f[0] = 1;
for (Int i = 0;i < m;++ i) read (x[i]);
for (Int i = 1;i <= n;++ i) C[i] = mul (C[i - 1],mul (n - i + 1,qkpow (i,mod - 2)));
for (Int i = 0;i <= x[m - 1] + n;++ i)
for (Int S = 0;S < (1 << m);++ S)
for (Int j = 0;j < m;++ j)
if (!(S >> j & 1) && x[j] <= i && i <= x[j] + n)
f[S | (1 << j)] = (__builtin_parity(S >> j) ? dec (f[S | (1 << j)],mul (f[S],C[i - x[j]])) : add (f[S | (1 << j)],mul (f[S],C[i - x[j]])));
write (mul (f[(1 << m) - 1],qkpow (mod + 1 >> 1,n * m))),putchar ('
');
return 0;
}