# bzoj 4517: [Sdoi2016]排列计数

## 4517: [Sdoi2016]排列计数

Time Limit: 60 Sec  Memory Limit: 128 MB
Submit: 637  Solved: 396
[Submit][Status][Discuss]

## Description

1 ~ n 这 n 个数在序列中各出现了一次

## Input

T=500000，n≤1000000，m≤1000000

5
1 0
1 1
5 2
100 50
10000 5000

0
1
20
578028887
60695423

## Source

Fn=(n-1)(Fn-1+Fn-2)

 1 #include<bits/stdc++.h>
2 #define LL long long
3 const int oo = 0x3f3f3f3f;
4 template <class T> inline bool Chkmin(T &x, T y) { return x > y ? x = y, true : false; }
5 template <class T> inline bool Chkmax(T &x, T y) { return x < y ? x = y, true : false; }
6 template <class T> inline T read(T &x)
7 {
8     static int f;
9     static char c;
10     for (f = 1; !isdigit(c = getchar()); ) if (c == '-') f = -f;
11     for (x = 0; isdigit(c); c = getchar()) x = x * 10 + c - 48;
12     return x *= f;
13 }
14 template <class T> inline void write(T x, char P = 0)
15 {
16     static char s[20];
17     static int top = 0;
18     if (x < 0) x = -x, putchar('-');
19     do {s[++top] = x % 10 + 48;} while (x /= 10);
20     do {putchar(s[top]);} while (--top);
21     if (P) putchar(P);
22 }
23
24 static const int MAXN = 1e6;
25 static const int MO = 1e9 + 7;
26
27 static int T, N, M;
28 static int Jc[MAXN + 5], Ni[MAXN + 5], f[MAXN + 5];
29
30 inline int Qpow(int x, int n)
31 {
32     int ans = 1;
33     while (n) {
34         if (n & 1) ans = (LL) ans * x % MO;
35         x = (LL) x * x % MO;
36         n >>= 1;
37     }
38     return ans;
39 }
40
41 int main()
42 {
43     Ni[0] = Jc[0] = 1;
44     for (register int i = 1; i <= MAXN; ++ i) {
45         Jc[i] = (LL) Jc[i - 1] * i % MO;
46         Ni[i] = Qpow(Jc[i], MO - 2);
47     }
48     f[0] = 1; f[1] = 0;
49     for (register int i = 2; i <= MAXN; ++ i) {
50         f[i] = (LL) (f[i - 1] + f[i - 2]) * (i - 1) % MO;
51     }
52     for (read(T); T--; ) {
57 }