今天做ZOJ月赛,最水的那道题却没做出来原题是
Give a set S, |S| = n, then how many ordered set group (S1, S2, ..., Sk) satisfies S1 ∩ S2 ∩ ... ∩ Sk = ∅. (Si is a subset of S, (1 <= i <= k))
Input
The input contains multiple cases, each case have 2 integers in one line represent n and k(1 <= k <= n <= 231-1), proceed to the end of the file.
Output
Output the total number mod 1000000007.
Sample Input
1 1 2 2
Sample Output
1 9当时一看就开始盘算考虑要把有没有空集分开考虑,然后列了各种情况神马的。。觉得巨麻烦,然后就这样一直纠结着。。。
比完赛后,在群里问了一下,有人提到了“ 考虑把每个元素在每个子集中的情况 ”,我才恍然大悟。。。
由于每个元素对计数的贡献都是相等的,所以可以从个体对象全体,得到总共的数量。即 (2^k - 1) ^ n化繁为简,十分漂亮.
这种思想在计数问题中很常见,要注意多思考多总结啊