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 浪里个浪
...
随机推荐
- C# Newtonsoft.Json 解析多嵌套json 进行反序列化
[ { ", "time": "2016-09-09 12:23:33", ", "freeShipping": tru ...
- 【转载】char*,const char*和string 三者转换
本文转自 http://blog.csdn.net/perfumekristy/article/details/7027678 const char* 和string 转换 const char*转换 ...
- Linux中的代码编辑器vim
Vim的三种工作模式 命令行模式 插入模式 底行模式 Vim 的命令行模式 命令行模式是进入vim后的初始模式,在该模式下主要是使用方向键来移动光标的位置,并通过相应的命令来进行文字的编辑. 切换方法 ...
- 标签种类及CSS引入方法
标签种类及CSS引入方法 标签种类: 一:块级标签(block) ——> 独占一行,默认宽度与内容无关,宽高可设 (hr 块级标签) 二:行内块标签(inline-block) ——> ...
- PHP递归操作
对于php的递归操作解释说明,递归基本上是学习每种语言都要会的最基本的操作.来吧,下面是我闲的时候随便写的一个对数组进行遍历操作的一个递归函数. 原理很简单,递归就是在一个函数里面调用自身的一种机制. ...
- PLC状态机编程第五篇-状态机自动生成PLC程序
这篇比较简单了,我就直接上图了,不多废话. 一.选择求解器,一定要选择定步长的. 二.右击Chart状态机,出现图上菜单 三.左边红色的勾选择,选择右侧的菜单,然后点击Generate Code按钮, ...
- A Country on Wheels【车轮上的国家】
A Country on Wheels As cultural symbols go, the American car is quite young. 作为文化象征的美国汽车还相当年轻. The ...
- C语言基础篇(三) 指针
导航: 1.指针 2. 数组 3. 结构体,共用体 4. 内存分布图 5. 段错误分析 ----->x<------------->x<---- ...
- Partitioning by Palindromes UVA - 11584 简单dp
题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...
- Aizu:2200-Mr. Rito Post Office
快递 Time limit 8000 ms Memory limit 131072 kB Problem Description 你是某个岛国(ACM-ICPC Japan)上的一个苦逼程序员,你有一 ...