51nod 算法马拉松30 A.函数【容斥】【组合数学】
来源:互联网 发布:经纬度 数据库类型 编辑:程序博客网 时间:2024/06/05 15:47
Description
想知道f:A->B这个函数(其中|A|=n, |B|=m)的所有映射关系要使B的每个元素都要被A的一个元素覆盖到。
数字可能很大你只要输出方案数模1,000,000,007即可。
题解
枚举有在B中有几个元素一定被映射到了,假设B中有
代码
#include<cstdio>#include<cstring>#include<algorithm>#define maxn 1000006#define tt 1000000007#define LL long longusing namespace std;int n,m;LL ans,f[maxn],inv[maxn];LL power(LL x,int y){ if(!y)return 1; if(y==1)return x%tt; LL c=power(x,y>>1); if(y&1)return c*x%tt*c%tt; else return c*c%tt;}LL C(int x,int y){return f[x]*inv[y]%tt*inv[x-y]%tt;}int main(){ freopen("function.in","r",stdin); freopen("function.out","w",stdout); scanf("%d%d",&n,&m); if(n<m)return printf("0\n"),0; f[0]=inv[0]=1; for(int i=1;i<=m;i++)(f[i]=f[i-1]*i)%=tt; inv[m]=power(f[m],tt-2); for(int i=m-1;i>=1;i--)inv[i]=inv[i+1]*(i+1)%tt; for(int i=0;i<m;i++)(ans+=C(m,i)*power(m-i,n)%tt*((i&1)?-1:1))%=tt; printf("%lld\n",(ans+tt)%tt); return 0;}
阅读全文
0 0
- 51nod 算法马拉松30 A.函数【容斥】【组合数学】
- 51nod 序列变换 [容斥原理+莫比乌斯函数]【数论+组合数学】
- [容斥原理+组合数学]51 Nod 1829——函数
- 51nod 算法马拉松19 A P1674
- 51nod 1829 函数(组合数+容斥)
- [数学] 51Nod 1622 算法马拉松19 C 集合对
- 51nod 1824(算法马拉松30)
- 51nod 算法马拉松3 A:序列分解
- 51nod 算法马拉松11 A 翻硬币
- 【51Nod算法马拉松18 A】染色问题
- 【51nod 算法马拉松19 A】区间的价值 V2
- [状态压缩||折半搜索]51nod 算法马拉松3 A
- 51NOD 1806 wangyurzee的树(容斥原理 + 组合数学)
- 51 nod 1486 大大走格子 容斥原理+组合数学+dp
- 51nod 1486 大大走格子(组合数学+容斥)
- 51nod 算法马拉松12
- 51nod算法马拉松20
- 51Nod 算法马拉松23
- 博客收藏oracle
- Gradle使用指南--webapp项目
- Hello csdn
- SENSORO与Google Eddystone覆盖全操作系统 用Web世界的思路打开物联网世界
- python3 list列表的常用方法
- 51nod 算法马拉松30 A.函数【容斥】【组合数学】
- 腾讯众创空间社会价值盘点: 拉动 490 亿元经济增长
- 亿人关注:全球首款6GB运存vivo Xplay5今晚发布
- 树莓派3B+ 云音乐(AirPlay)
- 用Notepad++在线编写集群配置文件
- spring和mybatis整合
- TCP-关闭机制
- UML中的事物
- 如何拼接GET请求的参数