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 fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define vpii vector<pii>
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const int N = 2005;
const int M = 1000000007;
ll dp[N][N];
void solve(){
ll n,cs,cf,a = 0;
cin >> n >> cs >> cf;
dp[1][1] = 1;
for(int i = 1; i <= n; i++){
if(n == cs || n == cf) a++;
for(int j = 1; j <= n; j++){
if(i == cs || i == cf){
dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % M;
dp[i][j] = (dp[i][j] + dp[i-1][j]) % M;
}
else{
dp[i][j] = (dp[i][j] + (dp[i-1][j-1] * (j-a)) % M)%M;
dp[i][j] = (dp[i][j] + (dp[i-1][j+1] * j) % M)%M;
}
}
}
cout << dp[n][1] << endl;
}
signed main(){
fast;
ll t = 1;
//cin >> t;
while(t--) solve();
}
# | 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... |