k-2

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

心已入冬 提交于 2019-12-05 12:29:47
F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1≤n≤2⋅105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. The problem is to finish n one-choice-questions. Each of the questions contains k options, and only one of them is correct. The answer to the i-th question is hi, and if your answer of the question i is hi, you earn 1 point, otherwise, you earn 0 points for this question. The values h1,h2,…,hn

Codeforces 1109D sasha and interesting fact from graph theory

倖福魔咒の 提交于 2019-12-02 03:24:13
题目链接: Codeforces1109D 题意 求满足以下条件的带标号树的个数: 边权在 \([1,m]\cap Z\) 点 \(a\) 到点 \(b\) 间的边权和为 \(m\) 数据范围: \(n,m≤1e6\) 题解 枚举 \(a\) , \(b\) 间点数为 \(i\) ,可以知道方案数为: \[ \dbinom{n - 2}{i}\dbinom{m-1}{i}i!m^{n-2-i} f(i) \] \(\dbinom{n-2}{i}i!\) 是在剩下 \(n-2\) 个点中选 \(i\) 个排在 \(a\) , \(b\) 之间。 \(\dbinom{m-1}{i}\) 是 \(i+1\) 条边和为 \(m\) 的方案数。 \(m^{n-2-i}\) 是不在 \(a\) , \(b\) 之间的点可以自由选择权值。 \(f(i)\) 是有一个长为 \(i+2\) 的链(以 \(a\) , \(b\) 为端点)和 \(n-i-2\) 个独立的点的生成树个数。 事实上,要计算 \(f(i)\) ,我们可以用一个更强的结论: 已知有 \(n\) 个点和 \(k\) 个联通的点集,第 \(i\) 个点集大小为 \(size[i]\) ,那么它生成树的个数为: \[ (\Pi_{i=1} ^ {k} size[i])n^{k-2} \] 设 \(P\) 是长度为 \(k-2\) 的