P7386 「EZEC-6」0-1 Trie 题解
很好的一道题,首先根据题目中对于1不能相邻的限制可以想到把10捆到一起考虑,于是现在trie树上的点可分为4类:
定义一类点的贡献为它在
对于
对于
两个同为
所以可以通过枚举每个
所以贡献为
(乘上的那个组合数就是
对于
式子为
贡献都计算出来了,直接枚举显然无法通过,考虑怎样化简
首先要知道对于这样一个式子
具体证明可以考虑第一个式子在辉三角上相当于一列斜着的,通过杨辉三角的性质逐行相加后可推出本式
所以对于一个这样的式子
带回上面两个式子后把四类点的贡献加起来就是
可通过
代码:
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i <= r; i ++)
#define pre(i, r, l) for(int i = r; i >= l; i --)
using namespace std;
typedef unsigned long long LL;
const LL P = 18888913;
LL fac[P + 10], inv[P + 10];
LL T, n, m, res;
inline LL read() {
LL x = 0; char c = getchar(); while(! isdigit(c)) c = getchar();
while(isdigit(c)) x = (x << 1) + (x << 3) + (LL)(c ^ 48), c = getchar();
return x;
}
LL ksm(LL x, LL y)
{
LL re = 1;
while(y)
{
if(y & 1) re = re * x % P;
x = x * x % P;
y >>= 1;
}
return re;
}
LL Lucas(LL x, LL y)
{
if(x < y || x < 0 || y < 0) return 0;
if(x < P && y < P) return (fac[x] * inv[y] % P) * inv[x - y] % P;
return Lucas(x / P, y / P) * Lucas(x % P, y % P) % P;
}
int main()
{
fac[0] = inv[0] = 1;
rep(i, 1, P - 1) fac[i] = fac[i - 1] * i % P;
inv[P - 1] = ksm(fac[P - 1], P - 2);
pre(i, P - 2, 1) inv[i] = inv[i + 1] * (i + 1) % P;
T = read();
while(T --)
{
n = read(), m = read();
if(n > m) continue;
LL ans = (Lucas(m, n) + Lucas(m, n - 1) * 2 % P) % P;
ans = (ans + Lucas(m - 1, n - 1)) % P;
ans = (ans + P - 2) % P;
res ^= ans;
}
printf("%llu\n", res);
return 0;
}