// In the name of God
// Hope is last to die
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())
const int maxn = 3000 + 5;
const int inf = 1e9 + 7, mod = 1e9 + 7;
ll n, m, dp[maxn][maxn];
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i <= m; i++) dp[0][i] = 1;
for(int i = 1; i <= n; i++){
dp[i][0] = 1;
for(int j = 1; j <= m; j++){
dp[i][j] = dp[i - 1][j];
ll c;
if(j > 1){
c = (j * (j - 1)) / 2;
c %= mod;
c = (c * dp[i - 1][j - 2]) % mod;
dp[i][j] = (dp[i][j] + c) % mod;
}
c = (j * 4 * dp[i - 1][j - 1]) % mod;
dp[i][j] = (dp[i][j] + c) % mod;
if(i > 1){
c = j * (i - 1) * dp[i - 2][j - 1];
c %= mod;
dp[i][j] = (dp[i][j] + c) % mod;
}
}
}
cout << (dp[n][m] + mod - 1) % mod << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
8 ms |
55844 KB |
Output is correct |
15 |
Correct |
59 ms |
66224 KB |
Output is correct |
16 |
Correct |
5 ms |
6488 KB |
Output is correct |
17 |
Correct |
14 ms |
16980 KB |
Output is correct |
18 |
Correct |
19 ms |
29276 KB |
Output is correct |
19 |
Correct |
68 ms |
70276 KB |
Output is correct |
20 |
Correct |
55 ms |
57936 KB |
Output is correct |
21 |
Correct |
36 ms |
39508 KB |
Output is correct |
22 |
Correct |
38 ms |
51788 KB |
Output is correct |
23 |
Correct |
26 ms |
70492 KB |
Output is correct |
24 |
Correct |
90 ms |
70992 KB |
Output is correct |
25 |
Correct |
68 ms |
62036 KB |
Output is correct |
26 |
Correct |
77 ms |
68180 KB |
Output is correct |
27 |
Correct |
88 ms |
70224 KB |
Output is correct |