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 _ ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
using namespace std;
const int N = 2001, M = 1e9 + 7;
int n, a, b, i, j, dp[N][N];
signed main()
{_
cin >> n >> a >> b; dp[1][1] = 1;
for (i = 2; i <= n; i++)
for (j = 1; j <= i; j++)
if (i == a || i == b) dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % M;
else dp[i][j] = (dp[i - 1][j + 1] * j + dp[i - 1][j - 1] * (j - (a < i) - (b < i))) % M;
return cout << dp[n][1], 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... |