QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#31176#2573. Two Permutationsleeh18AC ✓268ms11448kbC++201.3kb2022-05-04 02:51:112022-05-04 02:51:12

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 02:51:12]
  • 评测
  • 测评结果:AC
  • 用时:268ms
  • 内存:11448kb
  • [2022-05-04 02:51:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int mod = 1000000007;
int dp[2][101][10001];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= m; k++) {
                dp[i&1][j][k] = 0;
                if (n-2*i+j+2 >= 2) {
                    dp[i&1][j][k] += (long long)dp[(i&1)^1][j][k] * (n-2*i+j+2) * (n-2*i+j+1) % mod;
                    if (dp[i&1][j][k] >= mod) {
                        dp[i&1][j][k] -= mod;
                    }
                }
                if (j >= 1 && k >= i && (n-2*i+j+1) >= 0) {
                    dp[i&1][j][k] += (long long)dp[(i&1)^1][j-1][k-i] * (n-2*i+j+1) * (2*i-2*j+1) % mod;
                    if (dp[i&1][j][k] >= mod) {
                        dp[i&1][j][k] -= mod;
                    }
                }
                if (j >= 2 && k >= 2*i && i-j+1 >= 0) {
                    dp[i&1][j][k] += (long long)dp[(i&1)^1][j-2][k-2*i] * (i-j+1) * (i-j+1) % mod;
                    if (dp[i&1][j][k] >= mod) {
                        dp[i&1][j][k] -= mod;
                    }
                }
            }
        }
    }
    cout << dp[n&1][n][m] << '\n';
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 5656kb

input:

2 4

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 3ms
memory: 5608kb

input:

3 7

output:

12

result:

ok 1 number(s): "12"

Test #3:

score: 0
Accepted
time: 3ms
memory: 5732kb

input:

4 10

output:

24

result:

ok 1 number(s): "24"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5716kb

input:

4 14

output:

96

result:

ok 1 number(s): "96"

Test #5:

score: 0
Accepted
time: 3ms
memory: 5676kb

input:

5 10

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 3ms
memory: 7648kb

input:

5 15

output:

120

result:

ok 1 number(s): "120"

Test #7:

score: 0
Accepted
time: 3ms
memory: 5692kb

input:

5 21

output:

2400

result:

ok 1 number(s): "2400"

Test #8:

score: 0
Accepted
time: 0ms
memory: 5760kb

input:

6 21

output:

720

result:

ok 1 number(s): "720"

Test #9:

score: 0
Accepted
time: 3ms
memory: 5612kb

input:

6 30

output:

25920

result:

ok 1 number(s): "25920"

Test #10:

score: 0
Accepted
time: 3ms
memory: 5660kb

input:

6 27

output:

106560

result:

ok 1 number(s): "106560"

Test #11:

score: 0
Accepted
time: 1ms
memory: 7796kb

input:

20 300

output:

644873710

result:

ok 1 number(s): "644873710"

Test #12:

score: 0
Accepted
time: 4ms
memory: 7800kb

input:

20 139

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 5ms
memory: 7720kb

input:

30 470

output:

491424690

result:

ok 1 number(s): "491424690"

Test #14:

score: 0
Accepted
time: 2ms
memory: 7984kb

input:

30 500

output:

8436035

result:

ok 1 number(s): "8436035"

Test #15:

score: 0
Accepted
time: 4ms
memory: 5968kb

input:

40 1000

output:

617159088

result:

ok 1 number(s): "617159088"

Test #16:

score: 0
Accepted
time: 8ms
memory: 8016kb

input:

40 900

output:

729805907

result:

ok 1 number(s): "729805907"

Test #17:

score: 0
Accepted
time: 23ms
memory: 8192kb

input:

60 1830

output:

16340084

result:

ok 1 number(s): "16340084"

Test #18:

score: 0
Accepted
time: 24ms
memory: 8332kb

input:

60 2000

output:

832198921

result:

ok 1 number(s): "832198921"

Test #19:

score: 0
Accepted
time: 140ms
memory: 10024kb

input:

100 5050

output:

437918130

result:

ok 1 number(s): "437918130"

Test #20:

score: 0
Accepted
time: 23ms
memory: 8320kb

input:

100 700

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: 0
Accepted
time: 268ms
memory: 11448kb

input:

100 10000

output:

0

result:

ok 1 number(s): "0"