This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define sz(v) (ll)(v.size())
#define f first
#define s second
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
const ll mod = 1e9+7;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, cs, cf, i, j, c = 0;
cin >> n >> cs >> cf;
ll dp[n+5][n+5];
for(i = 0; i <= n; i++)
{
for(j = 0; j <= n; j++)
dp[i][j] = 0;
}
dp[1][1] = 1;
for(i = 1; i <= n; i++)
{
if(i == cs || i == cf)
c++;
for(j = 1; j < i; j++)
{
if(i == cs || i == cf)
{
dp[i][j] += dp[i-1][j];
dp[i][j+1] += dp[i-1][j];
dp[i][j] %= mod;
dp[i][j+1] %= mod;
}
else
{
dp[i][j-1] += dp[i-1][j] * (j-1);
dp[i][j+1] += dp[i-1][j] * (j + 1 - c);
dp[i][j-1] %= mod;
dp[i][j+1] %= mod;
}
}
}
cout << dp[n][1] % mod << "\n";
}
# | 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... |