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 all(v) v.begin(), v.end()
#define int long long
using namespace std;
const int sz = 2e3 + 4, mod = 1e9 + 7;
int n, s, f, dp[sz][sz];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s >> f;
int fixed = 0;
dp[1][1] = 1;
for(int i = 2; i <= n; i++)
{
if(i == s || i == f) fixed++;
for(int j = 1; j <= i; j++)
{
if(i == s || i == f)
{
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= mod;
dp[i][j] += dp[i - 1][j];
dp[i][j] %= mod;
}
else
{
dp[i][j] += dp[i - 1][j - 1] * (j - fixed) % mod;
dp[i][j] %= mod;
dp[i][j] += dp[i - 1][j] * (2 * j - fixed) % mod;
dp[i][j] %= mod;
dp[i][j] += dp[i - 1][j + 1] * j % mod;
dp[i][j] %= mod;
}
}
}
cout << dp[n][1];
}
# | 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... |