This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |