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;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 2e3 + 2;
constexpr int mod = 1e9 + 7;
int n, cs, cf, v;
int dp[N][N], f1[N][N];
void Read()
{
cin >> n >> cs >> cf;
if (cs > cf)
swap(cs, cf);
v = n - cf;
}
ll f(int n, int i)
{
if (dp[n][i] != -1)
return dp[n][i];
if (i == 1)
return dp[n][i] = (f1[n][n - v] + mod) % mod;
if (i == 2)
return dp[n][i] = ((f1[n][n - v] + f1[n - 1][n - 1 - v]) % mod + mod) % mod;
return dp[n][i] = (((2 * f(n, i - 1) % mod - f(n, i - 2)) % mod - f(n - 2, i - 2)) % mod + mod) % mod;
}
void Solve()
{
f1[2][2] = 1;
for (int i = 3; i <= n; ++i)
{
if (i & 1)
for (int j = 2; j < n; ++j)
(f1[i][2] += f1[i - 1][j]) %= mod;
for (int j = 3; j <= i; ++j)
f1[i][j] = (((i & 1) ? f1[i][j - 1] - f1[i - 1][j - 1] : f1[i][j - 1] + f1[i - 1][j - 1]) % mod + mod) % mod;
/*cout << i << ": ";
for (int j = 1; j <= i; ++j)
cout << f1[i][j] << " ";
cout << "\n";*/
}
memset(dp, -1, sizeof dp);
cout << (f(n, cs) % mod + mod) % mod;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
}
# | 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... |