FZU 2282 Wand(错排+费马小定理)
来源:互联网 发布:中高端女装品牌 知乎 编辑:程序博客网 时间:2024/06/11 01:11
Accept: 68 Submit: 250
Time Limit: 1000 mSec Memory Limit : 262144 KB
Problem Description
N wizards are attending a meeting. Everyone has his own magic wand. N magic wands was put in a line, numbered from 1 to n(Wand_i owned by wizard_i). After the meeting, n wizards will take a wand one by one in the order of 1 to n. A boring wizard decided to reorder the wands. He is wondering how many ways to reorder the wands so that at least k wizards can get his own wand.
For example, n=3. Initially, the wands are w1 w2 w3. After reordering, the wands become w2 w1 w3. So, wizard 1 will take w2, wizard 2 will take w1, wizard 3 will take w3, only wizard 3 get his own wand.
Input
First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.
For each test case: Two number n and k.
1<=n <=10000.1<=k<=100. k<=n.
Output
For each test case, output the answer mod 1000000007(10^9 + 7).
Sample Input
Sample Output
Source
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int N = 10000+2;#define LL long longconst LL p = 1e9+7;LL cp[N];LL k[N];void init(){ cp[1]=0; cp[2]=1; for(int i=3;i<=10000;i++) { (cp[i]=(i-1)*(cp[i-1]+cp[i-2]))%=p; } k[0]=1; for(int i=1;i<=10000;i++) { (k[i]=k[i-1]*i)%=p; }}LL qkm(LL base,LL mi){ LL ans=1; while(mi) { if(mi&1) (ans*=base)%=p; (base*=base)%=p; mi>>=1; } return ans;}LL C(int i,int n){ return ((k[n]*qkm((k[n-i]*k[i])%p,p-2))%p);//取模,两次!很关键k[n-i]*k[i]也会爆LL}int main(){ int n,k; int T; init(); scanf("%d",&T); while(T--) { scanf("%d %d",&n,&k); LL ans=1; for(int i=2;i<=n-k;i++) { (ans+=cp[i]*C(i,n))%=p; } printf("%lld\n",ans); }}
- FZU 2282 Wand(错排+费马小定理)
- FZU 2282 Wand(错排+费马小定理)
- FZU 2282Problem 2282 Wand(错排+快速幂+费马小定理)
- FZU 2282 Wand (组合数学 错排应用)
- FZU 2282 Wand(组合)
- FZU 2282 Wand,利用扩展欧几里得求逆元快速求C(n,m) , 错排公式推导
- fzu 2282 Wand
- FZU 2282 Wand 【组合数学】
- fzu-Wand
- fzu2282 wand 排列组合 错排
- FZU 2282 错排
- FZU 2282 错排问题dp
- FZU -- 2282 和 DHU -- 2049 【简单错排 + 组合数学】
- 第八届福建省大学生程序设计竞赛 K.Wand【错排+组合数】
- FZUOJ 2282 Wand
- FZU 2020 组合(Lucas定理)
- FZU 2020 组合(Lucas定理)
- fzu 2020 Lucas 定理
- 使用cocoapods导入第三方后 报错_OBJC_CLASS_$_XXX
- 浅谈UML---协作图
- RTMP直播到FMS中的AAC音频直播
- Android Launcher3修改应用图标,隐藏应用图标
- java基础购物选择数量计算,结算找零
- FZU 2282 Wand(错排+费马小定理)
- 自动装箱与拆箱的等于比较
- FARROW 滤波器
- struts2基本流程和action的对应
- 在把jQuery的ajax例子放在AppServ上运行时出错,failed to open stream: No such file or directory in Unknown on line 0
- Leetcode-Combination Sum ll(深搜)
- android下使用FTP上传文件、下载文件、新建目录、删除文件工具类
- Android Framework------之Keyguard 简单分析
- 办公技巧:PDF转DWG格式的两种简单方法