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 int long long
const int mod = 1e9 + 7;
int dp[2100][2100];
signed main(){
int n, st, fs;
cin >> n >> st >> fs;
dp[1][1] = 1;
for (int i = 2; i <= n; i++){
int cnt = 0;
if(i > st) cnt++;
if(i > fs) cnt++;
for(int j=1;j<=n;++j){
if(i == st || i == fs){
dp[i][j] = (dp[i][j] + dp[i-1][j] + dp[i-1][j-1]) % mod;
continue;
}
dp[i][j] = (((dp[i][j] + ((dp[i-1][j+1] * j) % mod))%mod) + ((((dp[i-1][j-1] * (j - cnt)) % mod) + mod) % mod));
}
}
cout << dp[n][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... |