#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m;
ll dp[3005][3005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
iloop(0, n+1) dp[i][0] = 1;
iloop(1, m+1) dp[0][i] = 1;
iloop(1, n+1) jloop(1, m+1) {
dp[i][j] = dp[i-1][j];
dp[i][j] += 4 * j * dp[i-1][j-1];
if (i >= 2) dp[i][j] += j * (i-1) * dp[i-2][j-1];
if (j >= 2) dp[i][j] += j * (j-1) / 2 * dp[i-1][j-2];
dp[i][j] %= MOD1;
}
cout << (dp[n][m] + MOD1 - 1)%MOD1;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |