函数
来源:互联网 发布:js display none 显示 编辑:程序博客网 时间:2024/06/16 10:05
知道f:A->B这个函数(其中|A|=n, |B|=m)的所有映射关系要使B的每个元素都要被A的一个元素覆盖到。
数字可能很大你只要输出方案数模1,000,000,007即可。
Input
一共一行两个数,n和m。(1<=n,m<=1,000,000)
Output
一共一行包含一个方案数。
Input示例
2 2
Output示例
2
思路:斯特林数
#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;const int MOD = 1e9 + 7;int n, m, a[MAXN], result;ll fac[MAXN], inv[MAXN];ll Pow(ll a,int b){ ll res = 1; while (b) { if (b & 1) { res = (res * a) % MOD; } b >>= 1; a = (a * 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(); cin >> n >> m; result = 0; for (int i = 0, e = 1; i <= m; i++) { result = (result + (e * Pow(m-i, n) * C(m, i)) % MOD) % MOD; e *= (-1); } cout << (result + MOD) % MOD << endl; return 0;}
阅读全文
0 0
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 机房收费系统之注册窗体
- Zookeeper工作原理(详细)
- Android图片加载框架最全解析(一),Glide的基本用法
- 如何通过jQuery实现select下拉框的联动效果
- 一些常用的加密解密、编码方法
- 函数
- 欢迎使用CSDN-markdown编辑器
- 【IntelliJ JDEA使用】使用IntelliJ JDEA新建java.class时,右键没有Class文件可选时处理方式
- Wifi网络判断
- python3之1002.写出这个数(20分)
- mac下将根目录/更改组到普通用户,导致sudo不能用
- 什么是面向对象?附带面向对象选项卡
- 邮箱,手机号,身份证的正则表达式
- LeetCode刷题 | 572. Subtree of Another Tree