이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// author: erray
#include<bits/stdc++.h>
using namespace std;
template<typename T, typename F> string to_string(pair<T, F> p);
string to_string(string s) {
return '"' + s + '"';
}
string to_string(char c) {
return (string) "'" + c + "'";
}
string to_string(const char* p) {
return to_string((string) p);
}
string to_string(bool B) {
return (B ? "true" : "false");
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < (int) v.size(); ++i) {
if ((int) res.size() > 1) res += ", ";
res += to_string(v[i]);
}
res += "}";
return res;
}
template<size_t T> string to_string(bitset<T> bs) {
return bs.to_string();
}
template<typename T> string to_string(T v) {
string res = "{";
for (auto& el : v) {
if ((int) res.size() > 1) res += ", ";
res += to_string(el);
}
res += "}";
return res;
}
template<typename T, typename F> string to_string(pair<T, F> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define debug(...) (void) 37
#endif
const int mod = (int) 1e9 + 7;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
vector<vector<long long>> dp(h + 1, vector<long long>(w + 1, 1LL));
auto get = [&](int x, int y) {
if (x < 0 || y < 0) return 0LL;
return dp[x][y];
};
for (int i = 1; i <= h; ++i) {
for (int j = 1; j <= w; ++j) {
dp[i][j] = dp[i - 1][j];
(dp[i][j] += get(i - 1, j - 1) * 4 * j % mod) %= mod;
(dp[i][j] += get(i - 2, j - 1) * (i - 1) % mod * j % mod) %= mod;
(dp[i][j] += get(i - 1, j - 2) * (j * (j - 1) / 2)) %= mod;
}
}
debug(dp);
cout << (dp[h][w] - 1 + mod) % mod << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |