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")// ceoi 2016 day 1 p2//03:11 11-25-2024
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define AI ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
ll dp[2001][2001];
int main()
{
AI
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll n,cs,cf,fixe=0,i,j,mod=1e9+7;
cin>>n;
cin>>cs>>cf;
dp[0][0]=1;
for(i=1;i<=n;i++)
{
if(i==cs or i==cf)
fixe++;
for(j=1;j<=n;j++)
{
if(i==cs or i==cf)
{
dp[i][j]+=dp[i-1][j-1];
dp[i][j]%=mod;
dp[i][j]+=dp[i-1][j];
dp[i][j]%=mod;
}
else
{
dp[i][j]+=(dp[i-1][j-1]*(j-fixe))%mod;
dp[i][j]+=(dp[i-1][j+1]*(j))%mod;
dp[i][j]%=mod;
}
}
// dp[2][1]=1;
// cout<<dp[i][1]<<' ';
}
cout<<dp[n][1]%mod;
}
# | 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... |