小w的喜糖 题目链接:https://lydsy.com/JudgeOnline/problem.php?id=4665 数据范围:略. 题解: 二项式反演裸题. $f_{i,j}$表示,前$i$种钦定$j$拿到自己种类糖果的方案数. 求完了之后可以二项式反演回来即可. 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1000000009 ; int n, m; ll…
http://codeforces.com/contest/111/problem/D Little Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size n × m (n rows, m columns) in k colors. Besides, the coloring should have the following proper…
CF997C Sky Full of Stars 计数好题 在Ta的博客查看 容斥式子:发现只要每个钦定方案的贡献都考虑到再配上容斥系数就是对的 O(n^2)->O(n) 把麻烦的i=0,j=0特殊考虑下 剩下的,先把麻烦的东西化简干净 然后枚举一维i,剩下的二项式定理!!!! #include<bits/stdc++.h> #define reg register int #define il inline #define fi first #define se second #def…
题意:小球排成一排,从m种颜色中选取k种颜色给n个球上色,要求相邻的球的颜色不同,求可行的方案数,答案模1e9+7.T组数据,1<= n, m <= 1e9, 1 <= k <= 1e6, k <= n, m 分析: a(k)表示用不超过k种颜色染n个位置,两两相邻颜色不相同的总数,很简单a(k)=k(n-1)^(k-1) b(k)表示恰好用k种颜色 很显然a(k)=ΣC(k,i)b(i),我们知道a,想知道b,这里就用到二项式反演 那么b(k)=ΣC(k,i)*i*(-1)…
传送门 为了方便我们设\(N\)是\(N,M,L\)中的最小值,某一个位置\((x,y,z)\)所控制的位置为集合\(\{(a,b,c) \mid a = x \text{或} b = y \text{或} c = z\}\) 发现恰好\(k\)个位置不大好算,考虑容斥计算强制\(k\)个位置是极大值的概率 对于极大值所在位置的数\(a_1,a_2,...,a_k\),假设\(a_1 > a_2 > ... > a_k\),那么我们还需要满足\(a_1 \geq a_1\)所在位置控制的…