首先注意到我们同一层不可能会修改多次比赛结果,因为 Sponsors 一定会定准一个目标然后修改结果,据此 \(k>n\) 可以视作 \(k=n\)。
因此某个叶子如果被选为冠军,那么根节点到叶子节点这条路上的边一定都被选中了,而如果某个叶子节点到根的路径上有小于等于 \(k\) 条边没有被选中,那么这个点可能会被 Sponsors 选为冠军,因此我们要让这些点编号都小,设答案为 \(ans\) 那么这些点的编号应为 \([1,ans]\)。
考虑会有多少点有小于等于 \(k\) 条边没被选中?枚举 \(i\) 表示某叶子节点到根节点路径上有 \(i\) 条边没有被选中,那么这类叶子节点个数就是 \(C_{n}^{i}\),但是至多只能修改 \(k\) 次结果,因此最终答案就是 \(\sum_{i=1}^{\min(n,k)}C_{n}^{i}\)。
GitHub:CodeBase-of-Plozia
Code:
/*
========= Plozia =========
Author:Plozia
Problem:CF1717D Madoka and The Corruption Scheme
Date:2022/9/5
========= Plozia =========
*/
#include <bits/stdc++.h>
typedef long long LL;
const int MAXN = 1e5 + 5;
const LL P = 1e9 + 7;
int n, k;
LL fact[MAXN], inv[MAXN];
int Read()
{
int sum = 0, fh = 1; char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar()) fh -= (ch == '-') << 1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ 48);
return sum * fh;
}
LL ksm(LL a, LL b = P - 2, LL p = P)
{
LL s = 1 % p;
for (; b; b >>= 1, a = a * a % p)
if (b & 1) s = s * a % p;
return s;
}
int main()
{
n = Read(), k = Read(); k = std::min(n, k);
fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = i * fact[i - 1] % P;
for (int i = 0; i <= n; ++i) inv[i] = ksm(fact[i]);
LL ans = 0;
for (int i = 0; i <= k; ++i) ans = (ans + fact[n] * inv[i] % P * inv[n - i] % P) % P;
printf("%lld\n", ans); return 0;
}
标签:ch,int,节点,叶子,Madoka,选中,Scheme,Corruption,Plozia
From: https://www.cnblogs.com/Plozia/p/16659665.html