This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Desinged by AzeTurk810 Open source
#include <bits/stdc++.h>
using namespace std;
# define ull unsigned long long
# define hurryup ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define endl '\n'
# define pb push_back
# define INF 1e10
# define vbol vector<bool>
# define vint vector<int>
# define ll long long
# define int long long
# define mod 1000000007
signed main()
{
int n,cs,cf,fixed = 0;
cin>>n>>cs>>cf;
vector<vector<int>>dp (n + 3,vector<int>(n + 3,0));
dp[1][1] = 1;
for(int i=1;i<=n;i++)
{
if(i == cs || i == cf) fixed++;
for(int 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- fixed);
dp[i][j-1] %= mod;
dp[i][j + 1] %= mod;
}
}
}
cout<<dp[n][1] % mod<<endl;
}
# | 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... |