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 = 210;
const ll mod = 1e9 + 7;
int n, s, f;
ll a[maxn][maxn][maxn];
ll d[maxn][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);
a[1][1][1] = d[1][1][1] = 1;
for (int l = 2; l <= n; l ++)
{
for (int i = 1; i <= l; i ++)
{
for (int j = 1; j <= l; j ++)
{
if (i == j)
continue;
if (i > 1 && i < j)
{
a[l][i][j] = (a[l][i - 1][j] - d[l - 1][i - 1][j - 1] + mod) % mod;
}
else if (i > j + 1)
{
a[l][i][j] = (a[l][i - 1][j] - d[l - 1][i - 1][j] + mod) % mod;
}
else
{
for (int g = i + 1; g <= n; g ++)
{
ll val = d[l - 1][g - 1][j - 1];
if (j < i)
val = d[l - 1][g - 1][j];
add(a[l][i][j], val);
}
}
if (i > 1 && i < j)
{
d[l][i][j] = (d[l][i - 1][j] + a[l - 1][i - 1][j - 1]) % mod;
}
else
if (i > j + 1)
{
d[l][i][j] = (d[l][i - 1][j] + a[l - 1][i - 1][j]) % mod;
}
else
{
for (int g = i - 1; g > 0; g --)
{
ll val = a[l - 1][g][j];
if (j > i)
val = a[l - 1][g][j - 1];
add(d[l][i][j], val);
}
}
///cout << l << " " << i << " " << j << " " << a[l][i][j] << " " << d[l][i][j] << endl;
}
}
}
ll ans = (d[n][s][f] + a[n][s][f]) % mod;
cout << ans << 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... |