Submission #157537

#TimeUsernameProblemLanguageResultExecution timeMemory
157537combi1k1Tents (JOI18_tents)C++14
100 / 100
123 ms35548 KiB
#include<bits/stdc++.h>

using namespace std;

const int   N   = 3e3 + 1;
const int   mod = 1e9 + 7;

void add(int &a,int b)  {
    a += b;
    if (a >= mod)
        a -= mod;
}
int mul(int a,int b)    {
    return  1ll * a * b % mod;
}

int f[N][N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int H;  cin >> H;
    int W;  cin >> W;

    for(int i = 0 ; i <  N ; ++i)
        f[i][0] = 1,
        f[0][i] = 1;

    for(int i = 1 ; i <= H ; ++i)
    for(int j = 1 ; j <= W ; ++j)   {
        int &res = f[i][j];
        add(res,f[i - 1][j]);
        add(res,mul(f[i - 1][j - 1],4 * j));
        if (i > 1)  add(res,mul(f[i - 2][j - 1],j * (i - 1)));
        if (j > 1)  add(res,mul(f[i - 1][j - 2],j * (j - 1) / 2));
    }

    cout << (f[H][W] + mod - 1) % mod;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...