Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation…
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…
题意:小球排成一排,从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)…