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 pb push_back
#define fi first
#define se second
#define bit(n,i) ((n>>i)&1)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll maxn=2000+69;
const ll mod=1e9+7;
const ll inf=1e18;
ll n,dp[maxn][maxn],cs,cf;
void add(ll& x , ll y)
{
x += y;
if(x >= mod)x -= mod;
}
void sol()
{
cin >> n>> cs>> cf;
dp[0][0]=1;
dp[1][0]=1;
for (int i=1;i<=n;i++)
{
for (int j=0;j<=n;j++)
{
if (i!=cs && i!=cf)
{
if (j>0) add(dp[i][j],dp[i-1][j-1]);
add(dp[i][j],dp[i-1][j+1]*(j+1)%mod*(j+(i>cs)+(i>cf))%mod);
}
else
{
add(dp[i][j],dp[i-1][j]);
add(dp[i][j],dp[i-1][j+1]*j%mod);
}
// cout <<i<<' '<<j<<' '<< dp[i][j]<<'\n';
}
//dp[1][0]=1;
}
cout <<dp[n][0];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;//cin >> t;
while (t--)
{
sol();
}
}
/*
6 7
0 1 0 2 1 2
1 3
3 6
1 2
2 4
2 5
5 6
1 6
*/
# | 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... |