제출 #797870

#제출 시각아이디문제언어결과실행 시간메모리
797870vjudge1Tents (JOI18_tents)C++17
100 / 100
188 ms35996 KiB
#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 3030;
const int mod = 1e9 + 7;

using namespace std;

void add(int &x, int y)
{
    x += y;
    if (x >= mod) {
        x -= mod;
    }
}

int d[N][N];

int main() {
    #ifdef zxc
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < N; i++) {
        d[0][i] = d[i][0] = 1;
    }
    for (int i = 1; i < N; i++) {
        d[1][i] = d[i][1] = i * 4 + i * (i - 1) / 2 + 1;
    }

    for (int i = 2; i <= n; i++) {
        for (int j = 2; j <= m; j++) {
            add(d[i][j], d[i - 1][j]);
            add(d[i][j], d[i - 1][j - 1] * 4ll % mod * j % mod);
            add(d[i][j], d[i - 1][j - 2] * (1ll * j * (j - 1) / 2 % mod) % mod);
            add(d[i][j], d[i - 2][j - 1] * (1ll * j * (i - 1) % mod) % mod);
        }
    }
    int res = d[n][m] - 1;
    if (res < 0) {
        res += mod;
    }
    cout << res << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...