mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 13:58:48 +00:00
4517. [SDOI2016] 排列计数
https://hydro.ac/d/bzoj/record/6322e6e932ae6c3198cc929b
This commit is contained in:
parent
fa7add2782
commit
592ff4f485
49
BZOJ/4517/4517.cpp
Normal file
49
BZOJ/4517/4517.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e6 + 5;
|
||||
const int mod = 1e9 + 7;
|
||||
|
||||
int t, n, m, fac[N], inv[N], fac_inv[N], d[N];
|
||||
|
||||
inline int C(int n, int m) {
|
||||
return static_cast<long long>(fac[n]) * fac_inv[m] % mod * fac_inv[n - m] % mod;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
fac[0] = 1;
|
||||
for (int i = 1; i < N; i++) {
|
||||
fac[i] = static_cast<long long>(fac[i - 1]) * i % mod;
|
||||
}
|
||||
|
||||
inv[0] = inv[1] = 1;
|
||||
for (int i = 2; i < N; i++) {
|
||||
inv[i] = static_cast<long long>(mod - (mod / i)) * inv[mod % i] % mod;
|
||||
}
|
||||
|
||||
fac_inv[0] = fac_inv[1] = 1;
|
||||
for (int i = 2; i < N; i++) {
|
||||
fac_inv[i] = static_cast<long long>(fac_inv[i - 1]) * inv[i] % mod;
|
||||
}
|
||||
|
||||
d[2] = 1;
|
||||
for (int i = 3; i < N; i++) {
|
||||
d[i] = static_cast<long long>(i - 1) * (d[i - 1] + d[i - 2]) % mod;
|
||||
}
|
||||
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
cin >> n >> m;
|
||||
|
||||
cout << (n == m ? 1 : static_cast<long long>(d[n - m]) * C(n, m) % mod) << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/4517/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/11.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/11.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/12.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/12.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/13.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/13.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/14.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/14.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/15.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/15.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/16.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/16.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/17.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/17.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/18.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/18.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/19.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/19.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/20.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/20.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4517/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4517/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user