# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
151071 | karma | Tents (JOI18_tents) | C++14 | 11 ms | 8440 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N = int(1e3) + 2;
const int mod = int(1e9) + 7;
int f[N][N], n, m;
int add(int& x, int y) {if((x += y) >= mod) x -= mod;}
int mul(int x, int y) {return 1ll * x * y % mod;}
int DP(int r, int c)
{
if(f[r][c] != -1) return f[r][c];
if(r * c == 0) return f[r][c] = 1;
int& res = f[r][c];
res = DP(r - 1, c); // 0 in row r
add(res, mul(DP(r - 1, c - 1), 4 * c)); // 1 in row r
if(r >= 2) add(res, mul(DP(r - 2, c - 1), (r - 1) * c)); // 1 in row r, 1 in (r - 1) rows, same column
if(c >= 2) add(res, mul(DP(r - 1, c - 2), c * (c - 1) / 2)); // same row r
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
memset(&f, -1, sizeof f);
cin >> n >> m;
cout << (DP(n, m) - 1 + mod) % mod;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |