This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void addSelf(int &x, const int &y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
int add(int x, const int &y) {
addSelf(x, y);
return x;
}
void multSelf(int &x, const int &y) {
x = (int64_t)x * y % mod;
}
int mult(int x, const int &y) {
multSelf(x, y);
return x;
}
void testCase() {
int n, m;
cin >> n >> m;
vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = dp[i - 1][j]; /// nu pun nimic pe linia asta
if (j >= 1) { /// pun ceva doar pe linia asta, apoi tai linia si coloana
addSelf(dp[i][j], mult(dp[i - 1][j - 1], j * 4));
}
if (j >= 2) { /// pun 2 chestii pe linia asta, apoi tai linia si cele 2 coloane
addSelf(dp[i][j], mult(dp[i - 1][j - 2], j * (j - 1) / 2));
}
if (i >= 2 && j >= 1) { /// pun ceva si pe linia asta si pe o linie anterioara
addSelf(dp[i][j], mult(dp[i - 2][j - 1], j * (i - 1)));
}
}
}
cout << add(dp[n][m], mod - 1) << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |