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>
///#define int long long
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define pll pair<long long, long long>
#define mein ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using ii = pair<int,int>;
using ll = long long;
const int mod = 1e9 + 7;
const int N = 2005;
inline void fmin(int &x, int y){if(x > y)x=y;}
inline void fmax(int &x, int y){if(x < y)x=y;}
inline void add(int &x, int y){if((x+=y) >= mod)x-=mod;}
int n, cs, cf;
int dp[N][N];
int main(){
cin >> n >> cs >> cf;
dp[0][0] = 1;
for(int i = 1; i < n; i++){
if(i == cs ||i== cf){
for(int j = 0; j < i; j++)
add(dp[i][j], dp[i-1][j]);
for(int j = 0; j < i; j++)
add(dp[i][j-1], dp[i-1][j] * 1ll * j % mod);
} else {
for(int j = 0; j < i; j++){
if(j >= 2)
add(dp[i][j-1], dp[i-1][j] * 1ll * j % mod * 1ll * (j-1) % mod);
if(i >= cs)
add(dp[i][j-1],dp[i-1][j] * 1ll * j % mod);
if(i >= cf)
add(dp[i][j-1],dp[i-1][j] * 1ll * j % mod);
add(dp[i][j+1], dp[i-1][j]);
}
}
}
cout << dp[n-1][0] << 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... |