#include <bits/stdc++.h>
using namespace std;
long long dp[3001][3001];
bool visited[3001][3001];
long long MOD = 1e9 + 7;
long long f(int n, int m) {
if (n < 0 || m < 0) return 0;
if (n == 0 || m == 0) return 1;
if (visited[n][m]) return dp[n][m];
visited[n][m] = 1;
return dp[n][m] = (f(n - 1, m) + 4 * m * f(n - 1, m - 1) + f(n - 1, m - 2) * m * (m - 1) / 2 + f(n - 2, m - 1) * m * (n - 1)) % MOD;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
cout << (f(n, m) - 1 + MOD) % MOD << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
7004 KB |
Output is correct |
5 |
Correct |
0 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
7260 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
9308 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
9304 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
9564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
7004 KB |
Output is correct |
5 |
Correct |
0 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
7260 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
9308 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
9304 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
9564 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
8 ms |
35420 KB |
Output is correct |
15 |
Correct |
119 ms |
59476 KB |
Output is correct |
16 |
Correct |
2 ms |
7256 KB |
Output is correct |
17 |
Correct |
11 ms |
20824 KB |
Output is correct |
18 |
Correct |
32 ms |
27740 KB |
Output is correct |
19 |
Correct |
142 ms |
63828 KB |
Output is correct |
20 |
Correct |
108 ms |
52564 KB |
Output is correct |
21 |
Correct |
56 ms |
33952 KB |
Output is correct |
22 |
Correct |
72 ms |
43864 KB |
Output is correct |
23 |
Correct |
47 ms |
49236 KB |
Output is correct |
24 |
Correct |
181 ms |
67668 KB |
Output is correct |
25 |
Correct |
131 ms |
57428 KB |
Output is correct |
26 |
Correct |
169 ms |
63352 KB |
Output is correct |
27 |
Correct |
192 ms |
65616 KB |
Output is correct |