This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 2010;
const ll mod = 1e9 + 7;
int n, s, f;
ll dp[maxn][maxn];
void add(ll &cell, ll val)
{
cell += val;
if (cell >= mod)
cell -= mod;
}
void solve()
{
cin >> n >> s >> f;
if (s > f)
swap(s, f);
dp[1][1] = 1;
for (int i = 2; i <= n; i ++)
{
for (int j = 1; j <= n; j ++)
if (i == s || i == f)
{
add(dp[i][j], dp[i - 1][j]);
add(dp[i][j], dp[i - 1][j - 1]);
}
else
{
ll ways = (dp[i - 1][j + 1] * j) % mod;
add(dp[i][j], ways);
ways = (dp[i - 1][j - 1] * (j - (s < i) - (f < i))) % mod;
add(dp[i][j], ways);
}
}
cout << dp[n][1] << endl;
}
int main()
{
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... |