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>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
const int N = 2000 + 5;
const int mod = 1e9 + 7;
int n, s, t;
int f[N][N];
void fix(int &a)
{
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
int dp(int i, int j)
{
if(j < 1) return 0;
if(i == 1) return j == 1;
int &res = f[i][j];
if(~res) return res;
res = 0;
if(i == s || i == t)
res = dp(i - 1, j - 1) + dp(i - 1, j), fix(res);
else
{
res += dp(i - 1, j - 1) * (j - (i > s) - (i > t)) % mod, fix(res);
res += dp(i - 1, j + 1) * (j) % mod, fix(res);
}
return res;
}
void solve()
{
cin >> n >> s >> t;
if(s > t) swap(s, t);
memset(f, -1, sizeof f);
cout << dp(n, 1);
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |