이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
#ifdef LOCAL
ifstream in("in.in");
ofstream out("out.out");
#else
#define in cin
#define out cout
#endif
const int nmax = 2005,mod = 1000000007;
int n,s,t;
int dp[nmax][nmax];
void addSelf(int &a, int b) {
a = (a + b) % mod;
}
int32_t main() {
in >> n >> s >> t;
if (s > t) {
swap(s,t);
}
dp[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (i != s && i != t) {
addSelf(dp[i][j] , dp[i - 1][j - 1] * (j - (i > s) - (i > t)));
addSelf(dp[i][j] , dp[i - 1][j + 1] * j);
} else {
addSelf(dp[i][j] , dp[i - 1][j - 1]); // we can make a new group with just i, or add this to the left-most
addSelf(dp[i][j] , dp[i - 1][j]);
}
}
}
out << dp[n][1] << "\n";
}
# | 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... |