题目链接
题目大意
你有一张无穷大的二维矩阵,你的出发点在格点(0,ai),并且保证了出发点横坐标依次递增:你的目标点分别是(1,0),(2,0)…(n,0),你有几个出发点就有几个目标点,求从出发点去目标点走过的路径没有任何交点的方案数。
说得挺详细的
lgv引理,后面用 线性代数知识 转化
最后fft卷一下
#include <bits/stdc++.h>
#define o(x) cout << (x) << endl;
using namespace std;
typedef long long LL;
const int N = 1 << 21, M = 1e6 + 1, mo = 998244353;
const double PI = acos(-1);
int n, m;
struct Complex{
double x, y;
Complex operator+ (const Complex& t) const {
return {x + t.x, y + t.y};
}
Complex operator- (const Complex& t) const {
return {x - t.x, y - t.y};
}
Complex operator* (const Complex& t) const {
return {x * t.x - y * t.y, x * t.y + y * t.x};
}
}a[N], b[N];
int rev[N], bit, tot;
void fft(Complex a[], int inv) {
for (int i = 0; i < tot; i ++ )
if (i < rev[i])
swap(a[i], a[rev[i]]);
for (int mid = 1; mid < tot; mid <<= 1) {
auto w1 = Complex({cos(PI / mid), inv * sin(PI / mid)});
for (int i = 0; i < tot; i += mid * 2) {
auto wk = Complex({1, 0});
for (int j = 0; j < mid; j ++ , wk = wk * w1) {
auto x = a[i + j], y = wk * a[i + j + mid];
a[i + j] = x + y, a[i + j + mid] = x - y;
}
}
}
}
LL qmi(LL a, LL k) {
LL res = 1;
while(k) {
if (k & 1) res = res * a % mo;
a = a * a % mo;
k >>= 1;
}
return res;
}
LL inv[N];
int main() { //o(M * log2(M))
LL res = 1, num = 1;
inv[1] = inv[0] = 1;
int nn;
scanf("%d", &nn);
for (int i = 1; i <= nn; i ++ ) {
int x; scanf("%d", &x);
res = res * (x + 1) % mo;
if (i > 1) inv[i] = (mo - mo / i) * inv[mo % i] % mo;
num = num * inv[i] % mo;
res = res * num % mo;
a[x + 1].x = 1;
b[M - (x + 1)].x = 1;
}
n = 1e6 + 1, m = 1e6 + 1; //o(res)
while((1 << bit) < n + m + 1) bit ++ ;
tot = 1 << bit;
for (int i = 0; i < tot; i ++ )
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
fft(a, 1), fft(b, 1);
for (int i = 0; i < tot; i ++ ) a[i] = a[i] * b[i];
fft(a, -1);
for (int i = M + 1; i <= n + m; i ++ ) {
int k = int(a[i].x / tot + 0.5);
if (k) {
res = res * qmi(abs(i - M), k) % mo;
}
}
printf("%lld\n", res);
return 0;
}