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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 1000000007
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll mul(ll x, ll y){return (x*y)%mod;}
ll add(ll x, ll y){return (x+y)%mod;}
bool bio[3005][3005];
ll dp[3005][3005];
ll resi(ll x, ll y){
if(x == 0 || y == 0)return 1;
if(bio[x][y])return dp[x][y];
bio[x][y] = 1;
ll tmp = 0;
tmp = add(resi(x - 1, y), tmp);
tmp = add(mul(resi(x - 1,y - 1), 4*y), tmp);
ll bruh = (y * (y - 1)) / 2;
bruh %= mod;
ll tmp1 = 0;
if(x && y >= 2)tmp1 = mul(resi(x - 1, y - 2), bruh);
bruh = mul(x - 1 , y);
ll tmp2 = 0;
if(x >= 2 && y)tmp2 = mul(resi(x - 2, y - 1), bruh);
tmp = add(tmp, tmp1);
tmp = add(tmp, tmp2);
return dp[x][y] = tmp;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n,m;
cin >> n >> m;
cout << (resi(n,m) - 1 + mod)%mod << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |