Submission #798081

#TimeUsernameProblemLanguageResultExecution timeMemory
798081bonkTents (JOI18_tents)C++14
100 / 100
256 ms71156 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 3002; const ll mod = 1e9 + 7; ll dp[N][N]; ll multi(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; } ll add(ll a, ll b){ return (a + b) % mod; } ll f(ll x, ll y){ if(x < 0 || y < 0) return 0; if(x == 0 || y == 0) return 1; auto &cur = dp[x][y]; if(cur != -1) return cur; cur = add( add( add( f(x - 1, y), multi(4LL*y, f(x - 1, y - 1)) ), multi((y*(y - 1LL))/2LL, f(x - 1, y - 2)) ), multi(y*(x - 1LL), f(x - 2, y - 1)) ); return cur; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dp, -1, sizeof(dp)); int h, w; cin >> h >> w; cout << (f(h, w) - 1LL + mod) % mod << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...