病毒扩散
https://ac.nowcoder.com/acm/contest/5205/B
https://ac.nowcoder.com/discuss/416603
思路:
排列组合。完全想不到,这个问题可以这样转换,完全不明白啊……😭(tcl)
答案:
C
t
x
×
C
t
−
x
y
C_t^x \times C_{t-x}^{y}
Ctx×Ct−xy
或者像题解说的这样
看题解不懂但是求组合数还是会的,就当练习一下
715 m s / 198424 K B 715ms / 198424KB 715ms/198424KB ,预处理 C n m C_n^m Cnm
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5005;
const ll mod = 998244353LL;
ll c[N][N];
void init()
{
for (int i = 0; i < N; i++)
c[i][0] = 1LL;
for (int i = 1; i < N; i++)
for (int j = 1; j < N; j++)
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
int main()
{
#ifdef LOCAL_LIUZHIHAN
freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
#endif
int n, x, y, t;
cin >> n;
init();
while (n--)
{
cin >> x >> y >> t;
if (t < x + y)
cout << 0 << endl;
else
cout << (c[t][x] % mod * c[t - x][y] % mod) << endl;
}
return 0;
}
228 m s / 1376 K B 228ms/1376KB 228ms/1376KB ,预处理 n ! n! n! 以及它的逆元
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353LL;
const int N = 5005;
ll fac[N], invfac[N];
ll qpow(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans % mod;
}
ll get_inv(ll a, ll p)
{
return qpow(a, p - 2);
}
void init()
{
fac[0] = invfac[0] = 1;
for (int i = 1; i < N; i++)
{
fac[i] = fac[i - 1] * i % mod;
invfac[i] = get_inv(fac[i], mod);
}
}
int main()
{
#ifdef LOCAL_LIUZHIHAN
freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
#endif
init();
int n, x, y, t;
cin >> n;
while (n--)
{
cin >> x >> y >> t;
if (t < x + y)
cout << 0 << endl;
else
cout << (fac[t] * invfac[x] % mod * invfac[y] % mod * invfac[t - x - y] % mod) << endl;
}
return 0;
}