foj Problem 2282 Wand
Accept: 432 Submit: 1537
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
1 1
3 1
Sample Output
4
Source
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
#include<set>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
#define N_MAX 10000+4
#define MOD 1000000007
#define INF 0x3f3f3f3f
typedef long long ll;
int n, k;
ll dp[N_MAX];//错排数
ll C[N_MAX][ + ];
void init() {
dp[] = ; dp[] = ; dp[] = ;
for (int i = ; i < N_MAX; i++) {
dp[i] = ((i - )*(dp[i - ] + dp[i - ]) + MOD) % MOD;
}
}
void C_table() {
for (int i = ; i < N_MAX; i++) {
C[i][] = ;
for (int j = ; j <= min(, i); j++) {//!!!j<=i并且数组中j不能超过100
C[i][j] = (C[i - ][j] + C[i - ][j - ]) % MOD;
}
}
} int main() {
init(); C_table();
int t; scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &k);
ll num = , ans = ;
for (ll i = ; i <= n; i++) {
ans = ans*i%MOD;
}
for (int i = ; i <= k - ; i++) {
num = (num + C[n][i] * dp[n - i]) % MOD;
}
printf("%lld\n", (ans - num + MOD) % MOD);
}
return ;
}
foj Problem 2282 Wand的更多相关文章
- FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod C Accept: 1368 Submit: 4639Time Limit: 1000 mSec Memory Limit : 32 ...
- FOJ Problem 1016 无归之室
Problem 1016 无归之室 Accept: 926 Submit: 7502Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- FOJ Problem 1015 土地划分
Problem 1015 土地划分 Accept: 823 Submit: 1956Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- foj Problem 2107 Hua Rong Dao
Problem 2107 Hua Rong Dao Accept: 503 Submit: 1054Time Limit: 1000 mSec Memory Limit : 32768 K ...
- FOJ Problem 2273 Triangles
Problem 2273 Triangles Accept: 201 Submit: 661Time Limit: 1000 mSec Memory Limit : 262144 KB P ...
- foj Problem 2275 Game
Problem D Game Accept: 145 Submit: 844Time Limit: 1000 mSec Memory Limit : 262144 KB Problem D ...
- foj Problem 2283 Tic-Tac-Toe
Prob ...
- FOJ Problem 2257 Saya的小熊饼干
...
- FOJ Problem 2261 浪里个浪
...
随机推荐
- composer安装教程(Linux版)
composer 是款不错的工具,那么如何进行安装composer呢 如果您是linux系统或是mac系统 请先确定是否安装了curl linux安装curl 1 yum install -y c ...
- 判断移动端和pc端最简单的方法
<!DOCTYPE html><html><head> <title></title> <script type="text ...
- 利用pandas和numpy计算表中每一列的均值
import numpy as np import pandas as pd df = pd.DataFrame({'var1':np.random.rand(100), #生成100个0到1之间的随 ...
- 17-比赛2 F - Fox And Two Dots (dfs)
Fox And Two Dots CodeForces - 510B ================================================================= ...
- MySQL常用命令基础操作
MySQL启动与更改密码 mysql启动基本原理说明: /etc/init.d/mysqld是一个shell启动脚本,启动后最终会调用,mysqld_safe脚本,最后调用mysqld服务启动mysq ...
- 常用数据库连接URL地址大全
1.Oracle8/8i/9i数据库(thin模式) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); ...
- 剑指Offer - 九度1373 - 整数中1出现的次数(从1到n整数中1出现的次数)
剑指Offer - 九度1373 - 整数中1出现的次数(从1到n整数中1出现的次数)2014-02-05 23:03 题目描述: 亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直 ...
- 添加selenium对应的jar包至pom.xml
1.进入https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java,点开相应的版本 2.复制图中选中的代码,粘贴至 ...
- NGUI-UIScroll View的使用及注意点
项目层次: scrollviewbg是600x150的背景图,Inspector视图如下: panel就是scrollview父容器了,size为600x150,Inspector视图如下: item ...
- 牛客网暑期ACM多校训练营(第一场):D-Two Graphs
链接:D-Two Graphs 题意:给出图G1和G2,求G2的子图中和G1同构的个数. 题解:只有8个点,暴力枚举G2的点每个排列,让G1映射到G2中,求出同构个数a.同构的G2就是在G1有边的对应 ...