QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#36039 | #2573. Two Permutations | conqueror_of_zky# | AC ✓ | 81ms | 57400kb | C++ | 950b | 2022-06-23 14:52:37 | 2022-06-23 14:52:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 105, K = 10005, mod = 1e9 + 7;
int n, k, f[N][N][K];
inline int mul(int a, int b) {return 1ll * a * b % mod;}
inline int add(int a, int b) {return (a += b) >= mod ? a - mod : a;}
inline void upd(int &a, int b) {a = add(a, b);}
int main() {
//freopen("in.txt", "r", stdin);
cin >> n >> k;
k -= n * (n + 1) / 2;
if(k < 0) {
cout << 0 << '\n';
return 0;
}
f[n][0][0] = 1;
for(int i = n; i >= 1; i --) {
for(int j = 0; j <= n - i; j ++) {
for(int l = 0; l < n * n; l ++) if(f[i][j][l]) {
upd(f[i - 1][j][l], mul(j + 1, f[i][j][l]));
if(l + i < n * n) upd(f[i - 1][j + 1][l + i], mul(j + 1, f[i][j][l]));
if(j && l >= i) upd(f[i - 1][j - 1][l - i], mul(f[i][j][l], j));
upd(f[i - 1][j][l], mul(j, f[i][j][l]));
}
}
}
int ans = f[0][0][k];
for(int i = 1; i <= n; i ++) ans = mul(ans, i);
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 7768kb
input:
2 4
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 3ms
memory: 9716kb
input:
3 7
output:
12
result:
ok 1 number(s): "12"
Test #3:
score: 0
Accepted
time: 2ms
memory: 11836kb
input:
4 10
output:
24
result:
ok 1 number(s): "24"
Test #4:
score: 0
Accepted
time: 4ms
memory: 11780kb
input:
4 14
output:
96
result:
ok 1 number(s): "96"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3552kb
input:
5 10
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 11888kb
input:
5 15
output:
120
result:
ok 1 number(s): "120"
Test #7:
score: 0
Accepted
time: 2ms
memory: 11792kb
input:
5 21
output:
2400
result:
ok 1 number(s): "2400"
Test #8:
score: 0
Accepted
time: 4ms
memory: 11828kb
input:
6 21
output:
720
result:
ok 1 number(s): "720"
Test #9:
score: 0
Accepted
time: 1ms
memory: 11744kb
input:
6 30
output:
25920
result:
ok 1 number(s): "25920"
Test #10:
score: 0
Accepted
time: 4ms
memory: 11924kb
input:
6 27
output:
106560
result:
ok 1 number(s): "106560"
Test #11:
score: 0
Accepted
time: 2ms
memory: 12600kb
input:
20 300
output:
644873710
result:
ok 1 number(s): "644873710"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3556kb
input:
20 139
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 2ms
memory: 14016kb
input:
30 470
output:
491424690
result:
ok 1 number(s): "491424690"
Test #14:
score: 0
Accepted
time: 7ms
memory: 13896kb
input:
30 500
output:
8436035
result:
ok 1 number(s): "8436035"
Test #15:
score: 0
Accepted
time: 3ms
memory: 15772kb
input:
40 1000
output:
617159088
result:
ok 1 number(s): "617159088"
Test #16:
score: 0
Accepted
time: 3ms
memory: 15956kb
input:
40 900
output:
729805907
result:
ok 1 number(s): "729805907"
Test #17:
score: 0
Accepted
time: 12ms
memory: 22664kb
input:
60 1830
output:
16340084
result:
ok 1 number(s): "16340084"
Test #18:
score: 0
Accepted
time: 4ms
memory: 22584kb
input:
60 2000
output:
832198921
result:
ok 1 number(s): "832198921"
Test #19:
score: 0
Accepted
time: 81ms
memory: 57396kb
input:
100 5050
output:
437918130
result:
ok 1 number(s): "437918130"
Test #20:
score: 0
Accepted
time: 2ms
memory: 3700kb
input:
100 700
output:
0
result:
ok 1 number(s): "0"
Test #21:
score: 0
Accepted
time: 63ms
memory: 57400kb
input:
100 10000
output:
0
result:
ok 1 number(s): "0"