Submission #362325

#TimeUsernameProblemLanguageResultExecution timeMemory
362325knightron0Tents (JOI18_tents)C++14
100 / 100
448 ms71404 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second #define clr(a, x) memset(a, x, sizeof(a)) #define dbg(x) cout<<"("<<#x<<"): "<<x<<endl; #define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl; #define all(v) v.begin(), v.end() #define lcm(a, b) (a * b)/__gcd(a, b) #define int long long int #define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl; #define endl '\n' #define float long double const int MOD = 1e9 + 7; const int INF = 2e15; const int MAXN = 3005; int n, m; int dp[MAXN][MAXN]; int modinv = 0; int fastexpo(int b, int exp){ if(exp == 0) return 1; if(exp == 1) return b; int ans = (fastexpo(b,exp/2) % MOD); ans *= ans; ans %= MOD; if(exp % 2 == 1){ ans *= b; } ans %= MOD; return ans; } int nc2(int n){ int ans = n%MOD; ans *= (n-1+MOD)%MOD; ans %= MOD; return ans*modinv; } int f(int lx, int ly){ if(lx < 0 || ly < 0) return 0; if(lx == 0 || ly == 0) return 1; if(dp[lx][ly] != -1) return dp[lx][ly]; return dp[lx][ly]= (((4*((lx%MOD)*(f(lx-1, ly-1)%MOD))%MOD)%MOD) + ((((ly-1)%MOD)*(lx%MOD)*(f(lx-1, ly-2)%MOD)%MOD)%MOD) + ((nc2(lx)%MOD)*(f(lx-2,ly-1)%MOD)%MOD) + ((f(lx, ly-1)%MOD)%MOD))%MOD; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif cin>>n>>m; clr(dp, -1); modinv = fastexpo(2, MOD-2); cout<<(f(n, m)+MOD-1)%MOD<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...