#题面
#题目描述
During your participation in this competition, Shinyruo is preparing to order KFC for the offline competition next week.
There are kinds of foods in KFC, and he plans to order number of the -th food for every . Due to shortage of manpower, the total number of all kinds of foods is no larger than .
After the competition, he will hand all the KFC out to teams. Each team can get different kinds of foods but for each kind it can get one at most. Now Shinyruo wants to know the number of ways to hand the desserts out. As he doesn’t know the number of participating teams, you need to calculate the answers for . As the answer can be large, print it modulo .
#输入格式
The first line contains two integers . ()
The second line contains integers . (, )
#输出格式
lines each contains one integer. The -th integer indicates the answer of modulo .
#输入输出样例
样例输入 #1
4 6
0 1 2 3
样例输出 #1
0
0
9
96
500
1800
#思路
一共有 种食物,每种食物有 个。食物个数总和不超过 。
现在要把所有食物分给 个人,每个人可以拿多种食物,但每种食物最多拿 个。
对于人数 从 到 ,分别输出食物分配方案数。
答案对 取模。
对于「一种食物共有 个,全部分给 个人,每人最多分一个」,就相当于「从 人中选出 人每人拿一个」,则第 种食物的方案数为 。
那么将 种食物分给 个人的总方案为 。
然而这样做的时间复杂度为 ,会超时,因此需要进行一些优化。从数据范围中得知 ,因此 的种类数在 的级别,使用 unordered_map + 快速幂去重即可。
#代码
1 |
|