voidinit(){ mul[1] = mul[0] = 1; for (int i = 1; i <= 100; i++) (mul[i] = mul[i - 1] * i) %= mod; C[0][0] = 1; for (int i = 1; i <= 100; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j < i; j++) { C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; //printf("C[%lld][%lld] = %lld\n", i, j, C[i][j]); } } }
intf(int n, int k){ int res = mul[n - k + 1]; int sum = 0; for (int i = 0; i < k; i++) { (sum += C[n - k][i] * C[k][i + 1]) %= mod; } return res * sum; } intmain(){ for (int i = 1; i <= 100; i++) { for (int k = 1; k <= i; k++) { printf("f[%d][%d] = %d\n", i, k, f(i, k)); } } } }
int L, R, s, type;
namespace subtask1 { constint mod = 998244353; intpower(int a, int b){ int res = 1; while (b) { if (b & 1) { (res *= a) %= mod; } (a *= a) %= mod; b >>= 1; } return res; } intinv(int x){ returnpower(x, mod - 2); } intcalc(int n, int k){ int res = 1; for (int i = n; i <= n + k; i++) { (res *= i) %= mod; } (res *= inv(k + 1)) %= mod; return res; } voidformat(int &res){ if (res < 0) res += (-res / mod + 1) * mod; res %= mod; } signedmain(){ int res = calc(R, s + 1) - calc(L - 1, s + 1); format(res); cout << res << endl; return0; } }
namespace subtask2 { constint mod = 998244353; constint MAXN = 1e7 + 10; structValue { int x, y, a, b; Value() { x = 0, y = 0, a = 0, b = 0; } }; int n = 0; int inv[MAXN]; Value calc(int k){ Value res; if (k > 0) { Value prev = calc(k - 1); res.y = prev.y * (k + 1) % mod * (n + k + 1) % mod * inv[k + 2] % mod; res.x = (mod - k - 1) * prev.b % mod; res.a = (res.y + res.x) % mod * inv[2] % mod; res.b = (res.y - res.x + mod) % mod * inv[2] % mod; } else { res.y = ((1 + n) % mod) * n % mod * inv[2] % mod; res.a = n * n % mod * inv[4] % mod; res.b = ((n + 2) % mod) * n % mod * inv[4] % mod; res.x = (res.a - res.b + mod) % mod; } return res; } voidformat(int &res){ if (res < 0) res += (-res / mod + 1) * mod; res %= mod; } signedmain(){ inv[1] = 1; for (int i = 2; i <= s + 10; i++) { inv[i] = inv[mod % i] * (mod - mod / i) % mod; } int l = L, r = R; if ((l + r) % 2 == 0) { if ((l + s) % 2 == 0) l++; else r++; } n = r; Value res = calc(s); int ans = 0; if ((l + s) % 2 == 1) { ans += res.a; } else { ans += res.b; } n = l - 1; res = calc(s); if ((l + s) % 2 == 1) ans -= res.a; else ans -= res.b; format(ans); cout << ans << endl; return0; } }
signedmain(){ fastin >> L >> R >> s >> type; if (type == 1) return subtask1::main(); return subtask2::main(); }
leaflike
给定整点,曼哈顿距离为偶数之间的点有连边,另有给定的 m 条边,求该图最大团。
很妙的题。
考虑将点按 (abs(x)+abs(y))mod2 分成两类。对于 m = 0 的情况就是两类点个数取 max