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 int long long
#define inf 0x3F3F3F3F3F3F3F3F
const int MXN = 500 + 5;
const int mod = 1e9 + 7;
int n, cs, cf;
int dp[MXN][MXN][MXN];
int f(int m, int x, int y, int t)
{
if (m == 2)
{
if (t == 0) return x > y;
else return x < y;
}
if (dp[m][x][y] != -1) return dp[m][x][y];
int res = 0;
for (int i = 1; i <= m; i++)
{
if (i == x || i == y) continue;
if ((i < x) && t == 0) res = (res + f(m - 1, i, (y > x ? y - 1 : y), t ^ 1)) % mod;
if ((i > x) && t == 1) res = (res + f(m - 1, i - 1, (y > x ? y - 1 : y), t ^ 1)) % mod;
}
return dp[m][x][y] = res;
}
void _()
{
cin >> n >> cs >> cf;
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) dp[i][j][k] = -1;
cout << (f(n, cs, cf, 0) + f(n, cs, cf, 1)) % mod << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) _();
}
# | 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... |