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 MOD=1e9+7;
int n, s, e;
int dp[2001], dp2[2001];
int mult(int a, int b){
return ((long long )a*b)%MOD;
}
int add(int &a, int b){
a+=b;
if(a>=MOD) a-=MOD;
return a;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
// freopen("kangaroo.in", "r", stdin);
// freopen("kangaroo.out", "w", stdout);
cin >> n >> s >> e;
dp[0]=1;
for(int i=1; i<=n; i++){
for(int j=0; j<i; j++){
if(!dp[j]) continue;
if(i==s || i==e){
add(dp2[j+1], dp[j]);
if(j) add(dp2[j], dp[j]);
continue;
}
add(dp2[j+1], mult(dp[j], (j+1-(i>s)-(i>e))));
if(j>=2) dp2[j-1]+=mult(dp[j], j-1);
}
for(int j=0; j<=i; j++){
dp[j]=dp2[j];
dp2[j]=0;
}
}
cout << dp[1];
}
# | 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... |