排列计数(bzoj 4517)
Description
Input
Output
输出 T 行,每行一个数,表示求出的序列数
Sample Input
1 0
1 1
5 2
100 50
10000 5000
Sample Output
1
20
578028887
60695423
/*
很容易就推出公式:ans=C(n,m)*dp[n-m]
dp[i]表示i的全错排方案数,dp[i]=(i-1)*(dp[i-1]+dp[i-2])
预处理出阶乘,阶乘的逆元和dp数组。
*/
#include<cstdio>
#include<iostream>
#define N 1000010
#define lon long long
#define mod 1000000007
#ifdef unix
#define LL "%lld"
#else
#define LL "%I64d"
#endif
using namespace std;
lon dp[N],inv[N],jc1[N],jc2[N],n,m;
void init(){
dp[]=;dp[]=;dp[]=;
for(int i=;i<N;i++)
dp[i]=(i-)*(dp[i-]+dp[i-])%mod;
inv[]=;
for(int i=;i<N;i++)
inv[i]=(mod-mod/i)*inv[mod%i]%mod;
jc1[]=;
for(int i=;i<N;i++)
jc1[i]=jc1[i-]*i%mod;
jc2[]=;
for(int i=;i<N;i++)
jc2[i]=jc2[i-]*inv[i]%mod;
}
int main(){
init();
int T;scanf("%d",&T);
while(T--){
scanf(LL LL,&n,&m);
lon ans=jc1[n]*jc2[m]%mod*jc2[n-m]%mod*dp[n-m]%mod;
printf(LL,ans);printf("\n");
}
return ;
}
排列计数(bzoj 4517)的更多相关文章
- BZOJ 4517: [Sdoi2016]排列计数
4517: [Sdoi2016]排列计数 Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 911 Solved: 566[Submit][Status ...
- 数学(错排):BZOJ 4517: [Sdoi2016]排列计数
4517: [Sdoi2016]排列计数 Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 693 Solved: 434[Submit][Status ...
- BZOJ 4517: [Sdoi2016]排列计数 [容斥原理]
4517: [Sdoi2016]排列计数 题意:多组询问,n的全排列中恰好m个不是错排的有多少个 容斥原理强行推♂倒她 $恰好m个不是错排 $ \[ =\ \ge m个不是错排 - \ge m+1个不 ...
- BZOJ 4517: [Sdoi2016]排列计数 错排公式
4517: [Sdoi2016]排列计数 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4517 Description 求有多少种长度为 ...
- BZOJ 4517: [Sdoi2016]排列计数 错排+逆元
4517: [Sdoi2016]排列计数 Description 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i, ...
- Bzoj 4517: [Sdoi2016]排列计数(排列组合)
4517: [Sdoi2016]排列计数 Time Limit: 60 Sec Memory Limit: 128 MB Description 求有多少种长度为 n 的序列 A,满足以下条件: 1 ...
- bzoj-4517 4517: [Sdoi2016]排列计数(组合数学)
题目链接: 4517: [Sdoi2016]排列计数 Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 846 Solved: 530[Submit][ ...
- BZOJ 4517--[Sdoi2016]排列计数(乘法逆元)
4517: [Sdoi2016]排列计数 Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 1727 Solved: 1067 Description ...
- bzoj 2111: [ZJOI2010]Perm 排列计数 (dp+卢卡斯定理)
bzoj 2111: [ZJOI2010]Perm 排列计数 1 ≤ N ≤ 10^6, P≤ 10^9 题意:求1~N的排列有多少种小根堆 1: #include<cstdio> 2: ...
- BZOJ 2111: [ZJOI2010]Perm 排列计数 [Lucas定理]
2111: [ZJOI2010]Perm 排列计数 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1936 Solved: 477[Submit][ ...
随机推荐
- 《队长说得队》【Alpha】Scrum meeting 5
项目 内容 这个作业属于哪个课程 >>2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 >>实验十二 团队作业8:软件测试与ALPHA冲刺 团队名称 ...
- Neural Style论文笔记+源码解析
引言 前面在Ubuntu16.04+GTX1080配置TensorFlow并实现图像风格转换中介绍了TensorFlow的配置过程,以及运用TensorFlow实现图像风格转换,主要是使用了文章A N ...
- SpringMVC 项目中引用其他 Module 中的方法
1. 将要引用的Module 引入项目中 2. 在主Module中添加依赖, 3. 被引用的类必须放在 Module 中/src/下的某个package中,否则引用不到(重要)
- 在VUE中,关于CKEditor使用
官方文档 语言配置 代码如下 ClassicEditor .create( document.querySelector( '#editor' ), { language: 'de' // 配置语言 ...
- python3.7 文件操作
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 文件操作 # r 只读,默认打开方式,当文件不存在时会报错 # ...
- LeetCode(172)Factorial Trailing Zeroes
题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- 安装openstack同步数据库时出错解决方法
错误提示:(2003, "Can't connect to MySQL server on 'controller' ([Errno -2] Name or service not know ...
- python 提交form-data之坑
#coding=utf-8 import requests from requests_toolbelt import MultipartEncoder #requests库上传 files = {& ...
- cf963b Destruction of a Tree
越靠近叶子越优先删掉 #include <iostream> #include <vector> #include <cstdio> using namespace ...
- luogu3388 【模板】割点(割顶)
模板题 #include <iostream> #include <cstdio> using namespace std; struct Edge{ int too, nxt ...