fzu2282 Wand 数学
来源:互联网 发布:网络课幸福心理学答案 编辑:程序博客网 时间:2024/06/14 07:02
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
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)错位排序
预处理逆元
import java.io.BufferedInputStream;import java.io.PrintWriter;import java.util.Scanner;public class Main {public static void main(String[] args) {new Task().solve();}}class Task {Scanner in = new Scanner(new BufferedInputStream(System.in)) ;PrintWriter out = new PrintWriter(System.out);final long Mod = 1000000007L ;final int N = 10000 ;long[] D = new long[N+1] ;long[] inv = new long[N+1] ;void solve(){D[0] = 1 ;D[1] = 0 ;D[2] = 1 ;for(int i = 3 ; i <= N ; i++){ D[i] = (i-1) * ((D[i-2] + D[i-1]) % Mod) % Mod ;}inv[1] = 1; for(int i = 2 ; i <= N ; i++){ inv[i] = (Mod - Mod / i) % Mod * inv[(int)Mod % i] % Mod ; } int t = in.nextInt() ;while(t-- > 0){long n = in.nextLong() ;long k = in.nextLong() ;long C = 1 ;for(int i = 1 ; i < k ; i++){C = C * inv[i] % Mod * (n-i+1) % Mod ;}long sum = 0 ; for(int i = (int)k ; i <= n ; i++){C = C * inv[i] % Mod * (n-i+1) % Mod ;sum = sum + D[(int) (n-i)] * C % Mod ; sum %= Mod ;}out.println(sum) ;}out.flush() ;}}
- fzu2282 Wand 数学
- FZU2282-Wand
- 2017福建省赛FZU2282 Wand
- fzu2282 wand 排列组合 错排
- FZU 2282 Wand 【组合数学】
- FZU 2282 Wand (组合数学 错排应用)
- fzu-Wand
- FZU2282-组合数-逆元
- Wand的布鲁克纳第七
- Michael Wand 的个人主页
- fzu 2282 Wand
- FZUOJ 2282 Wand
- FZU 2282 Wand(组合)
- weak-and算法原理演示(wand)
- weak-and算法原理演示(wand)
- 【组合数+全错排】fzuoj 2282 Wand
- NDk 1409 佳佳的魔杖(Magic Wand)
- Python图片处理库Wand的简单使用
- 探秘Metaspace
- Javascript内置对象(2)
- 数据库——(9)外键
- 计算机网络基础知识
- thinkphp框架加载流程以及原理
- fzu2282 Wand 数学
- Python3基础-语句
- spring学习之---缓存机制
- Ubuntu14.04 + CUDA 8.0 +caffe
- 【技术维新 践行精彩】WebSphere7集群部署实践与总结
- 达内课程-面向对象之抽象类
- cf Petya and Exam(暴力)
- 【Linux】初窥Linux 之 我最常用的20条命令
- 二代身份证上的信息