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;
const int N=2005;
const int mod=1e9+7;
int n,cs,cf,dp[N][N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>cs>>cf;
if(cs>cf) swap(cs,cf);
dp[0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
if(i+1==cs||i+1==cf)
{
dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
if(j) dp[i+1][j-1]=(dp[i+1][j-1]+1ll*dp[i][j]*j%mod)%mod;
continue;
}
dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
if(j)
{
dp[i+1][j-1]=(dp[i+1][j-1]+1ll*j*(j-1)%mod*dp[i][j]%mod);
if(i+1>cs) dp[i+1][j-1]=(dp[i+1][j-1]+1ll*dp[i][j]*j%mod)%mod;
if(i+1>cf) dp[i+1][j-1]=(dp[i+1][j-1]+1ll*dp[i][j]*j%mod)%mod;
}
}
}
cout<<dp[n][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... |