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;
int dp[2005][2005];
const int MOD = 1e9 + 7;
int main()
{
int n, cs, cf;
cin >> n >> cs >> cf;
dp[0][0] = 1;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(i == cs || i == cf){ ///must put this at beggining or end
dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1]; ///(will link/wont link chain)
dp[i][j] %= MOD;
}else{
dp[i][j] = (1LL * dp[i - 1][j + 1] * j) % MOD + (1LL * dp[i - 1][j - 1] * (j - (i > cs) - (i > cf))) % MOD; ///if i > cs I cant put it before cs, if i > cf then I cant put it after it
dp[i][j] %= MOD;
}
}
}
cout << dp[n][1] << "\n";
return 0;
}
# | 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... |