#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 3003, M = N;
int n, m, dp[N][M];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(i == 1 && j == 1) {
dp[i][j] = 5;
} else if(i == 1) {
dp[i][j] = 1ll + j * 4 + j * (j - 1) / 2;
} else if(j == 1) {
dp[i][j] = 1ll + i * 4 + i * (i - 1) / 2;
} else if(j == 2 && i == 2) {
dp[i][j] = 53;
} else if(j == 2) {
dp[i][j] = (1ll + dp[i - 1][j] + 8ll * dp[i - 1][j - 1] + 2ll * dp[i - 2][j - 1]) % mod;
} else if(i == 2) {
dp[i][j] = (1ll + dp[i][j - 1] + 8ll * dp[i - 1][j - 1] + 2ll * dp[i - 1][j - 2]) % mod;
} else {
dp[i][j] = (1ll * dp[i - 1][j] + 4ll * j * dp[i - 1][j - 1] + 1ll * j * (i - 1) * dp[i - 2][j - 1] + 1ll * j * (j - 1) / 2 * dp[i - 1][j - 2]) % mod;
}
}
}
cout << (dp[n][m] + mod - 1) % mod;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |