#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 3e3 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m;
long long dp[MAXN][MAXN];
long long mod = 1e9 + 7;
void solve()
{
cin >> n >> m;
for (int i = 0; i <= n; ++ i)
dp[i][0] = 1;
for (int j = 0; j <= m; ++ j)
dp[0][j] = 1;
for (long long i = 1; i <= n; ++ i)
{
for (long long j = 1; j <= m; ++ j)
{
/// 0.
dp[i][j] = dp[i-1][j];
/// 1. x .... x
if(j >= 2)
{
dp[i][j] += (dp[i-1][j-2] * ((j * (j - 1) / 2) % mod)) % mod;
dp[i][j] %= mod;
}
/// 2. x
/// .
/// .
/// x
if(i >= 2)
{
dp[i][j] += dp[i-2][j-1] * (i-1) * j;
dp[i][j] %= mod;
}
/// 3. x
dp[i][j] += (dp[i-1][j-1] * j * 4) % mod;
dp[i][j] %= mod;
}
}
long long ans = (dp[n][m] + mod - 1) % mod;
cout << ans << endl;
}
int main()
{
speed();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
3 ms |
6620 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
3 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
3 ms |
6620 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
3 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
8536 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
18 ms |
55892 KB |
Output is correct |
15 |
Correct |
197 ms |
66268 KB |
Output is correct |
16 |
Correct |
13 ms |
6748 KB |
Output is correct |
17 |
Correct |
42 ms |
17004 KB |
Output is correct |
18 |
Correct |
54 ms |
29280 KB |
Output is correct |
19 |
Correct |
227 ms |
70384 KB |
Output is correct |
20 |
Correct |
178 ms |
59996 KB |
Output is correct |
21 |
Correct |
117 ms |
39516 KB |
Output is correct |
22 |
Correct |
116 ms |
51876 KB |
Output is correct |
23 |
Correct |
70 ms |
70408 KB |
Output is correct |
24 |
Correct |
307 ms |
71032 KB |
Output is correct |
25 |
Correct |
226 ms |
62044 KB |
Output is correct |
26 |
Correct |
262 ms |
68336 KB |
Output is correct |
27 |
Correct |
299 ms |
70396 KB |
Output is correct |