题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1829

本题目相当于:

n个不同的小球,放入到m个可区分的盒子中,且盒子不能

够为空,问方案数?

根据第二类斯特林数.答案就是 \(m!S(n,m)\);

再进行变化得: \(\sum_{i=0}^m (-1)^i(m-i)^n C_{m}^{i}\).

\(C_n^m = \frac{n!}{(n-m)!* m!}\)

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <string> using namespace std;
typedef long long int LL;
const int maxn=1000005,MOD=1e9+7; int n,m,a[maxn],ans;
LL fac[maxn],inv[maxn],fac_inv[maxn];
LL Pow(LL a,int b)
{
LL res=1;
for(; b; b>>=1,a=a*a%MOD) if(b&1) res=(res*a)%MOD;
return res;
}
LL C(int n,int m)
{
return fac[n]*Pow(fac[n-m]*fac[m]%MOD,MOD-2)%MOD;
} void init()
{
fac[0]=1;
for(int i=1; i<=1000000; i++) fac[i]=fac[i-1]*i%MOD;
inv[1]=1;
for(int i=2; i<=1000000; i++) inv[i]=(LL)(MOD-MOD/i)*inv[MOD%i]%MOD;
}
int main()
{
init();
scanf("%d%d",&n,&m);
ans=0;
for(int i=0,e=1; i<=m; i++,e*=-1)
ans=(ans+e*Pow(m-i,n)*C(m,i)%MOD)%MOD;
printf("%d\n",(ans+MOD)%MOD);
return 0;
}

51nod 1829(函数)的更多相关文章

  1. ACM基础算法入门及题目列表

    对于刚进入大学的计算机类同学来说,算法与程序设计竞赛算是不错的选择,因为我们每天都在解决问题,锻炼着解决问题的能力. 这里以TZOJ题目为例,如果为其他平台题目我会标注出来,同时我的主页也欢迎大家去访 ...

  2. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  3. 51nod 1244 莫比乌斯函数之和

    题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积 ...

  4. 51nod 1240 莫比乌斯函数

    题目链接:51nod 1240 莫比乌斯函数 莫比乌斯函数学习参考博客:http://www.cnblogs.com/Milkor/p/4464515.html #include<cstdio& ...

  5. 51nod 1244 莫比乌斯函数之和(杜教筛)

    [题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...

  6. 51nod 1239 欧拉函数之和(杜教筛)

    [题目链接] https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 [题目大意] 计算欧拉函数的前缀和 [题解] 我们 ...

  7. 51nod 1040 最大公约数之和(欧拉函数)

    1040 最大公约数之和 题目来源: rihkddd 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题   给出一个n,求1-n这n个数,同n的最大公约数的和.比如: ...

  8. 51nod 1244 莫比乌斯函数之和 【杜教筛】

    51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...

  9. 【51Nod 1239】欧拉函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 还是模板题. 杜教筛:\[S(n)=\frac{n(n+1)}{2 ...

随机推荐

  1. python pytest

    之前一直用unittest ,现在学习pytest 看看那个好 1. 安装 pip install -U pytest py.test --version 2. 只需要按照下面的规则: 测试文件以te ...

  2. Binding基础 文摘

    简要 Binding基础 Binding源与路径 列举Binding的源 Binding基础 从Coding中看Binding的基础. 先定义一个Student类: public class Stud ...

  3. python 正則表達式推断邮箱格式是否正确

    import re def validateEmail(email):     if len(email) > 7:         if re.match("^.+\\@(\\[?) ...

  4. Lifting the Stone(多边形重心)

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. Collective Mindsets (medium) (逻辑题)

    B - Collective Mindsets (medium) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I6 ...

  6. Residual (numerical analysis)

    In many cases, the smallness of the residual means that the approximation is close to the solution, ...

  7. Java基础 - 变量的定义和使用

    变量定义 public class Main { public static void main(String[] args) { // 定义byte类型的变量 byte b = 10; System ...

  8. 我的Android进阶之旅------>Android基于HTTP协议的多线程断点下载器的实现

    一.首先写这篇文章之前,要了解实现该Android多线程断点下载器的几个知识点 1.多线程下载的原理,如下图所示 注意:由于Android移动设备和PC机的处理器还是不能相比,所以开辟的子线程建议不要 ...

  9. Js遍历对象中的属性

    var obj = {"name": "xiaol","age":"18"} for(var attr in obj){ ...

  10. Django之表单验证

    对于前端的表单进行验证的方法,从最简单的js到基于XML传输的Ajax,再到cookie的免认证,现在Django为我们提供了自带的表单验证方法. views.py: from django impo ...