rt,思路是计算每一个障碍减少了多少路径。代码如下:
#include <iostream>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLLLL;
const int N = 310, M = 100010, MOD = 998244353;
int n, m, a, b, c, d, e, f;
int x[M], y[M];
int fact[N], infact[N];
set<PLLLL> st;
int qpow(int a, int b, int p)
{
int res = 1 % p;
while (b)
{
if (b & 1) res = (LL)res * a % p;
a = (LL)a * a % p, b >>= 1;
}
return res;
}
int ans;
void dfs(int u, LL x, LL y, int s, int i, int j, int k)
{
if (st.count({x, y}))
{
ans = (ans - (LL)fact[n - u] * infact[i] % MOD * infact[j] % MOD * infact[k] % MOD * qpow(3, u, MOD) % MOD + MOD) % MOD;
return ;
}
if (!u) return ;
dfs(u - 1, x + e, y + f, 2, i, j, k + 1);
if (s <= 1) dfs(u - 1, x + c, y + d, 1, i, j + 1, k);
if (!s) dfs(u - 1, x + a, y + b, 0, i + 1, j, k);
}
int main()
{
fact[0] = infact[0] = 1;
for (int i = 1; i < N; i ++ )
{
fact[i] = (LL)fact[i - 1] * i % MOD;
infact[i] = (LL)infact[i - 1] * qpow(i, MOD - 2, MOD) % MOD;
}
cin >> n >> m >> a >> b >> c >> d >> e >> f;
for (int i = 1; i <= m; i ++ ) cin >> x[i] >> y[i], st.insert({x[i], y[i]});
ans = qpow(3, n, MOD);
dfs(n, 0, 0, 0, 0, 0, 0);
cout << ans;
return 0;
}
AC 23,WA 7,求大佬们看看是怎么回事