From 592ff4f48503ef5ae47955d56f58dd66f38a85ab Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 15 Sep 2022 16:49:12 +0800 Subject: [PATCH] =?UTF-8?q?4517.=20[SDOI2016]=20=E6=8E=92=E5=88=97?= =?UTF-8?q?=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/6322e6e932ae6c3198cc929b --- BZOJ/4517/4517.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/4517/data/1.in | 3 +++ BZOJ/4517/data/1.out | 3 +++ BZOJ/4517/data/10.in | 3 +++ BZOJ/4517/data/10.out | 3 +++ BZOJ/4517/data/11.in | 3 +++ BZOJ/4517/data/11.out | 3 +++ BZOJ/4517/data/12.in | 3 +++ BZOJ/4517/data/12.out | 3 +++ BZOJ/4517/data/13.in | 3 +++ BZOJ/4517/data/13.out | 3 +++ BZOJ/4517/data/14.in | 3 +++ BZOJ/4517/data/14.out | 3 +++ BZOJ/4517/data/15.in | 3 +++ BZOJ/4517/data/15.out | 3 +++ BZOJ/4517/data/16.in | 3 +++ BZOJ/4517/data/16.out | 3 +++ BZOJ/4517/data/17.in | 3 +++ BZOJ/4517/data/17.out | 3 +++ BZOJ/4517/data/18.in | 3 +++ BZOJ/4517/data/18.out | 3 +++ BZOJ/4517/data/19.in | 3 +++ BZOJ/4517/data/19.out | 3 +++ BZOJ/4517/data/2.in | 3 +++ BZOJ/4517/data/2.out | 3 +++ BZOJ/4517/data/20.in | 3 +++ BZOJ/4517/data/20.out | 3 +++ BZOJ/4517/data/3.in | 3 +++ BZOJ/4517/data/3.out | 3 +++ BZOJ/4517/data/4.in | 3 +++ BZOJ/4517/data/4.out | 3 +++ BZOJ/4517/data/5.in | 3 +++ BZOJ/4517/data/5.out | 3 +++ BZOJ/4517/data/6.in | 3 +++ BZOJ/4517/data/6.out | 3 +++ BZOJ/4517/data/7.in | 3 +++ BZOJ/4517/data/7.out | 3 +++ BZOJ/4517/data/8.in | 3 +++ BZOJ/4517/data/8.out | 3 +++ BZOJ/4517/data/9.in | 3 +++ BZOJ/4517/data/9.out | 3 +++ 41 files changed, 169 insertions(+) create mode 100644 BZOJ/4517/4517.cpp create mode 100644 BZOJ/4517/data/1.in create mode 100644 BZOJ/4517/data/1.out create mode 100644 BZOJ/4517/data/10.in create mode 100644 BZOJ/4517/data/10.out create mode 100644 BZOJ/4517/data/11.in create mode 100644 BZOJ/4517/data/11.out create mode 100644 BZOJ/4517/data/12.in create mode 100644 BZOJ/4517/data/12.out create mode 100644 BZOJ/4517/data/13.in create mode 100644 BZOJ/4517/data/13.out create mode 100644 BZOJ/4517/data/14.in create mode 100644 BZOJ/4517/data/14.out create mode 100644 BZOJ/4517/data/15.in create mode 100644 BZOJ/4517/data/15.out create mode 100644 BZOJ/4517/data/16.in create mode 100644 BZOJ/4517/data/16.out create mode 100644 BZOJ/4517/data/17.in create mode 100644 BZOJ/4517/data/17.out create mode 100644 BZOJ/4517/data/18.in create mode 100644 BZOJ/4517/data/18.out create mode 100644 BZOJ/4517/data/19.in create mode 100644 BZOJ/4517/data/19.out create mode 100644 BZOJ/4517/data/2.in create mode 100644 BZOJ/4517/data/2.out create mode 100644 BZOJ/4517/data/20.in create mode 100644 BZOJ/4517/data/20.out create mode 100644 BZOJ/4517/data/3.in create mode 100644 BZOJ/4517/data/3.out create mode 100644 BZOJ/4517/data/4.in create mode 100644 BZOJ/4517/data/4.out create mode 100644 BZOJ/4517/data/5.in create mode 100644 BZOJ/4517/data/5.out create mode 100644 BZOJ/4517/data/6.in create mode 100644 BZOJ/4517/data/6.out create mode 100644 BZOJ/4517/data/7.in create mode 100644 BZOJ/4517/data/7.out create mode 100644 BZOJ/4517/data/8.in create mode 100644 BZOJ/4517/data/8.out create mode 100644 BZOJ/4517/data/9.in create mode 100644 BZOJ/4517/data/9.out diff --git a/BZOJ/4517/4517.cpp b/BZOJ/4517/4517.cpp new file mode 100644 index 00000000..94115b9e --- /dev/null +++ b/BZOJ/4517/4517.cpp @@ -0,0 +1,49 @@ +#include + +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(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(fac[i - 1]) * i % mod; + } + + inv[0] = inv[1] = 1; + for (int i = 2; i < N; i++) { + inv[i] = static_cast(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(fac_inv[i - 1]) * inv[i] % mod; + } + + d[2] = 1; + for (int i = 3; i < N; i++) { + d[i] = static_cast(i - 1) * (d[i - 1] + d[i - 2]) % mod; + } + + cin >> t; + + while (t--) { + cin >> n >> m; + + cout << (n == m ? 1 : static_cast(d[n - m]) * C(n, m) % mod) << endl; + } + + return 0; +} diff --git a/BZOJ/4517/data/1.in b/BZOJ/4517/data/1.in new file mode 100644 index 00000000..d1d6660c --- /dev/null +++ b/BZOJ/4517/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfaf0e3db0ae925388070f02778894cde405ed14d005a415435d76384e4f3204 +size 4005 diff --git a/BZOJ/4517/data/1.out b/BZOJ/4517/data/1.out new file mode 100644 index 00000000..91f294ff --- /dev/null +++ b/BZOJ/4517/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c6c1010d3f714fa5dd4988ea108be82dcc1ac3bf68b4eb46318b1ce4530ac09 +size 2741 diff --git a/BZOJ/4517/data/10.in b/BZOJ/4517/data/10.in new file mode 100644 index 00000000..b0ba7566 --- /dev/null +++ b/BZOJ/4517/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ce7b9d75f6bb7d0df708441859bdb80bbfb6f594153321f70d7f9064a15fd84 +size 5604 diff --git a/BZOJ/4517/data/10.out b/BZOJ/4517/data/10.out new file mode 100644 index 00000000..7a458fe4 --- /dev/null +++ b/BZOJ/4517/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83e46baeb3d3e0b59d24484e56e3c892a214155b235d918eb0694d02cd78c2dd +size 8435 diff --git a/BZOJ/4517/data/11.in b/BZOJ/4517/data/11.in new file mode 100644 index 00000000..07384464 --- /dev/null +++ b/BZOJ/4517/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ee064fbdcaa9c5b0c1056d1961c2d4eadfd0ec6ca29661664e7aca02d7e9fc4 +size 7534 diff --git a/BZOJ/4517/data/11.out b/BZOJ/4517/data/11.out new file mode 100644 index 00000000..70f9296b --- /dev/null +++ b/BZOJ/4517/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f8890ce830e1d7aec9ec885bc7d4458f56b83e82e83eaeb8d4ab5748996aecd +size 9692 diff --git a/BZOJ/4517/data/12.in b/BZOJ/4517/data/12.in new file mode 100644 index 00000000..ee2dfad8 --- /dev/null +++ b/BZOJ/4517/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:486b03e24f366f5256723365b9273726cc47b8acb4f9ae61b06020ca1a2ac259 +size 6747139 diff --git a/BZOJ/4517/data/12.out b/BZOJ/4517/data/12.out new file mode 100644 index 00000000..5d24f49c --- /dev/null +++ b/BZOJ/4517/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7465cf8b50f9163972748dc32cae6a8155d92ee9a7c71f269d9f456d2b20390c +size 4944530 diff --git a/BZOJ/4517/data/13.in b/BZOJ/4517/data/13.in new file mode 100644 index 00000000..082c5142 --- /dev/null +++ b/BZOJ/4517/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac4c0aedc023ac1a7f57b39c5897c81b0d1bf8a34890f6835fbfcc5df38bb42a +size 6746225 diff --git a/BZOJ/4517/data/13.out b/BZOJ/4517/data/13.out new file mode 100644 index 00000000..6de9ccae --- /dev/null +++ b/BZOJ/4517/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0db680bdd6934228d2efda6f4a956dea529cbd5272748d5cf951a5cbb143d22 +size 4944491 diff --git a/BZOJ/4517/data/14.in b/BZOJ/4517/data/14.in new file mode 100644 index 00000000..114b8ac5 --- /dev/null +++ b/BZOJ/4517/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47418ac855c9386eab2a0cffcfd1afcd2382d3290801cddf2469b7376d2a0fbb +size 4290 diff --git a/BZOJ/4517/data/14.out b/BZOJ/4517/data/14.out new file mode 100644 index 00000000..3b4cf85f --- /dev/null +++ b/BZOJ/4517/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f1466ade3caf132a090d71a5055688bfba8218ce684f3d0aa7e8846f2ed1b19 +size 3620 diff --git a/BZOJ/4517/data/15.in b/BZOJ/4517/data/15.in new file mode 100644 index 00000000..be172486 --- /dev/null +++ b/BZOJ/4517/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e16be7527e2ffc770d0b9d2603fc8bc4721b72ea8b4fb9032d30255d7f6d4d2d +size 4005 diff --git a/BZOJ/4517/data/15.out b/BZOJ/4517/data/15.out new file mode 100644 index 00000000..74d8c4e8 --- /dev/null +++ b/BZOJ/4517/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7cb40803bfa9f5884f708d0c8ea6f28bf944f5c03459ce2cad256e9438ad6940 +size 3136 diff --git a/BZOJ/4517/data/16.in b/BZOJ/4517/data/16.in new file mode 100644 index 00000000..3f72604f --- /dev/null +++ b/BZOJ/4517/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b90f9a2f05129af54d007de5f3bca27a707dd03bc99a69f029be99f4814017bd +size 7509 diff --git a/BZOJ/4517/data/16.out b/BZOJ/4517/data/16.out new file mode 100644 index 00000000..e8413735 --- /dev/null +++ b/BZOJ/4517/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b878131ad539db892c4ebf71a8c1ced9359d768060bad2b67bb6e1b6b6264e30 +size 9661 diff --git a/BZOJ/4517/data/17.in b/BZOJ/4517/data/17.in new file mode 100644 index 00000000..298f7a58 --- /dev/null +++ b/BZOJ/4517/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00c60f9ff826e74322a547ab44de830b2245d633b2b76fd09dbbbe374b968fd3 +size 6747111 diff --git a/BZOJ/4517/data/17.out b/BZOJ/4517/data/17.out new file mode 100644 index 00000000..1c9d0dea --- /dev/null +++ b/BZOJ/4517/data/17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d5c62858ad1440090fe610b3ac67c8497043ae1961a762f818b3f18fece282f3 +size 4944706 diff --git a/BZOJ/4517/data/18.in b/BZOJ/4517/data/18.in new file mode 100644 index 00000000..aff56426 --- /dev/null +++ b/BZOJ/4517/data/18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3d8ff18dab75880d0a7c2ababff041e05a16589d1cff10adcae4b51838112dc +size 6745993 diff --git a/BZOJ/4517/data/18.out b/BZOJ/4517/data/18.out new file mode 100644 index 00000000..14666def --- /dev/null +++ b/BZOJ/4517/data/18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66994292f4c832c1b112e59204d301106a83014687c91696a87f7dd9af342ea8 +size 4944337 diff --git a/BZOJ/4517/data/19.in b/BZOJ/4517/data/19.in new file mode 100644 index 00000000..fddf7054 --- /dev/null +++ b/BZOJ/4517/data/19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0555e5550695d8e5225382a2b2eeb171d1f2b9ecc89f22678f3e809a01af9fb +size 7523 diff --git a/BZOJ/4517/data/19.out b/BZOJ/4517/data/19.out new file mode 100644 index 00000000..eb5ad737 --- /dev/null +++ b/BZOJ/4517/data/19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ddb0a6be1ade512683e52b10c0b4b774bca71f824dbd47e6564cbf881f2bbb99 +size 9754 diff --git a/BZOJ/4517/data/2.in b/BZOJ/4517/data/2.in new file mode 100644 index 00000000..5089cfc8 --- /dev/null +++ b/BZOJ/4517/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8e0f9cdf26a33c4e6c66b0a2ce4b99abed10253bc9b8a4add73a4301de1b1d8 +size 3754619 diff --git a/BZOJ/4517/data/2.out b/BZOJ/4517/data/2.out new file mode 100644 index 00000000..0eadcfbe --- /dev/null +++ b/BZOJ/4517/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b34295bb61d376d666d198123295b5e92fbde2864264f3e67eb3827a96d2102 +size 4853279 diff --git a/BZOJ/4517/data/20.in b/BZOJ/4517/data/20.in new file mode 100644 index 00000000..763312a3 --- /dev/null +++ b/BZOJ/4517/data/20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:832d19288c7823646218e803e4c4e7b2071ce2481df76a6568e524a742173e67 +size 5609 diff --git a/BZOJ/4517/data/20.out b/BZOJ/4517/data/20.out new file mode 100644 index 00000000..fac24d2a --- /dev/null +++ b/BZOJ/4517/data/20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3b517527e3b0a0fa0d1f40549ced3ce13484e8611aceaf588e898b0422d254e +size 8518 diff --git a/BZOJ/4517/data/3.in b/BZOJ/4517/data/3.in new file mode 100644 index 00000000..27f70f88 --- /dev/null +++ b/BZOJ/4517/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8dabffd6d491101ae5085b5fd21cd965ceec790f0aa4aa2fbbc6ec15d9496a53 +size 3754774 diff --git a/BZOJ/4517/data/3.out b/BZOJ/4517/data/3.out new file mode 100644 index 00000000..d64482ed --- /dev/null +++ b/BZOJ/4517/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05ac899ceba21f5214d3879ecbd778ffdb38f24eedc369b42bad1da043b90cd8 +size 4852530 diff --git a/BZOJ/4517/data/4.in b/BZOJ/4517/data/4.in new file mode 100644 index 00000000..29ae7c8f --- /dev/null +++ b/BZOJ/4517/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3df49b172013b8643f61d3ba055f3b9b28d113381f769395b6ad620529d0886 +size 4289 diff --git a/BZOJ/4517/data/4.out b/BZOJ/4517/data/4.out new file mode 100644 index 00000000..32ce9d87 --- /dev/null +++ b/BZOJ/4517/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b87b0c1f27e4169b42d9c3bd7eebb705ea5e4fffd888a4ecf1cb32f15284b72 +size 3595 diff --git a/BZOJ/4517/data/5.in b/BZOJ/4517/data/5.in new file mode 100644 index 00000000..a3f6a780 --- /dev/null +++ b/BZOJ/4517/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2bb5ad16d95d212f0bdc16060c8b30b83036d97b492f8e007ef6696e07d8ddf9 +size 6746616 diff --git a/BZOJ/4517/data/5.out b/BZOJ/4517/data/5.out new file mode 100644 index 00000000..9d6da1c9 --- /dev/null +++ b/BZOJ/4517/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3978eeb28f64d19c14b4cc118b30a8a61e9396422750d22d6d23f275cd11ede4 +size 4944470 diff --git a/BZOJ/4517/data/6.in b/BZOJ/4517/data/6.in new file mode 100644 index 00000000..9aeccf82 --- /dev/null +++ b/BZOJ/4517/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77e6b787297267e6a33371d842f1edab9fa8653854db247ab4eef240cd58977d +size 5605 diff --git a/BZOJ/4517/data/6.out b/BZOJ/4517/data/6.out new file mode 100644 index 00000000..52d2e5c4 --- /dev/null +++ b/BZOJ/4517/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cfb48ec2c61f2e98a2d65dd92dccd5a89551a19095a6684ec75047e36db777aa +size 8393 diff --git a/BZOJ/4517/data/7.in b/BZOJ/4517/data/7.in new file mode 100644 index 00000000..ab52901a --- /dev/null +++ b/BZOJ/4517/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e0601186806be2b2a5982bc80861b1c3fa71899dc1093aab0afd61ba2d9d7cb +size 4005 diff --git a/BZOJ/4517/data/7.out b/BZOJ/4517/data/7.out new file mode 100644 index 00000000..680ddbbe --- /dev/null +++ b/BZOJ/4517/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02e9cd5be0e660795d43e580d5811b45963813235262dcdeee1a39638e0e7b2a +size 2681 diff --git a/BZOJ/4517/data/8.in b/BZOJ/4517/data/8.in new file mode 100644 index 00000000..73c3efcb --- /dev/null +++ b/BZOJ/4517/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cfeda818ae13617244b41dc5303df2a3d2682d863d8f3eaf6bedcd1d0438ce5d +size 6747111 diff --git a/BZOJ/4517/data/8.out b/BZOJ/4517/data/8.out new file mode 100644 index 00000000..56f660fc --- /dev/null +++ b/BZOJ/4517/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ac7ef42cad10c6472cc02afb5db3943adcc59f0610da6f88bc3451290ee93b7 +size 4944665 diff --git a/BZOJ/4517/data/9.in b/BZOJ/4517/data/9.in new file mode 100644 index 00000000..53e29a52 --- /dev/null +++ b/BZOJ/4517/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b4c09a149f9f05ceb2817de7c4c3a235aaae1c8ce9ff4e56e07f096a0f65b88f +size 4290 diff --git a/BZOJ/4517/data/9.out b/BZOJ/4517/data/9.out new file mode 100644 index 00000000..2682fe52 --- /dev/null +++ b/BZOJ/4517/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:efee0d6ae9a19108630272a7712e58101859563994af6fd96154b9140be8b981 +size 3522