# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101067 | ecasdqina | Tents (JOI18_tents) | C++14 | 323 ms | 71032 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;
const int MOD = 1e9 + 7;
i64 mod_pow(i64 x, i64 n = MOD - 2) {
i64 ret = 1;
while(n) {
if(n & 1) (ret *= x) %= MOD;
(x *= x) %= MOD;
n >>= 1;
}
return ret;
}
std::vector<i64> fact, inv;
i64 comb(int n, int r) {
return fact[n] * inv[n - r] % MOD * inv[r] % MOD;
}
int main() {
int h, w; scanf("%d%d", &h, &w);
// assert(h <= 300 and w <= 300);
fact.assign(std::max(h, w) + 1, 1); inv.assign(std::max(h, w) + 1, 1);
for(int i = 0; i < std::max(h, w); i++) fact[i + 1] = fact[i] * (i64)(i + 1) % MOD;
for(int i = 0; i <= std::max(h, w); i++) inv[i] = mod_pow(fact[i]);
std::vector<std::vector<i64>> dp(h + 1, std::vector<i64>(w + 1, 0));
dp[h][w] = 1;
for(i64 i = h; i >= 0; i--) {
for(i64 j = w; j >= 0; j--) {
if(i >= 1 and j >= 1) {
dp[i - 1][j - 1] += dp[i][j] * j % MOD * 4;
dp[i - 1][j - 1] %= MOD;
}
if(i >= 1 and j >= 2) {
dp[i - 1][j - 2] += dp[i][j] * comb(j, 2) % MOD;
dp[i - 1][j - 2] %= MOD;
}
if(i >= 2 and j >= 1) {
dp[i - 2][j - 1] += dp[i][j] * j % MOD * (i - 1) % MOD;
dp[i - 2][j - 1] %= MOD;
}
if(i >= 1) {
dp[i - 1][j] += dp[i][j];
dp[i - 1][j] %= MOD;
}
}
}
i64 ans = 0;
for(int j = 0; j <= w; j++) (ans += dp[0][j]) %= MOD;
printf("%lld\n", (ans - 1 + MOD) % MOD);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |