# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
392940 | cpp219 | Tents (JOI18_tents) | C++14 | 421 ms | 71376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 3e3 + 9;
const ll mod = 1e9 + 7;
ll x,y;
ll dp[N][N];
ll f(ll n,ll m){
if (n*m == 0) return m < y;
if (dp[n][m] != -1) return dp[n][m];
ll ans = 0;
if (m >= 2) ans = (ans + f(n - 1,m - 2)*m*(m - 1)/2)%mod;
ans = (ans + 4*m*f(n - 1,m - 1) + f(n - 1,m))%mod;
if (n >= 2) ans = (ans + f(n - 2,m - 1)*m*(n - 1))%mod;
return dp[n][m] = ans;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>x>>y; memset(dp,-1,sizeof(dp));
cout<<f(x,y);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |