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 ll long long
#define pii pair<int, int>
#define pll pair<ll ll>
#define st first
#define nd second
#define pb push_back
using namespace std;
const int maxN = 2e3 + 2;
const int M = 1e9 + 7;
ll dp[maxN][maxN];
void solve() {
int n, cf, cs, ct = 0; cin >> n >> cf >> cs;
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
if (i == cf || i == cs) ct++;
for (int j = 1; j <= n; ++j) {
if (i == cf || i == cs)
dp[i][j] = (dp[i][j] + dp[i-1][j] + dp[i-1][j-1]) % M;
else {
dp[i][j] = (dp[i][j] + (j-ct)*dp[i-1][j-1]) % M;
dp[i][j] = (dp[i][j] + j*dp[i-1][j+1]) % M;
}
}
}
cout << dp[n][1] << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int 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... |