이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
const int mod = 1000000007;
int f[N][N];
void add(int &x, int y) {
x += y; if (x >= mod) x -= mod;
}
int mul(int x, int y) {
return (long long) x * y % mod;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, cs, cf;
cin >> n >> cs >> cf;
f[1][1] = 1;
for (int i = 2; i <= n; ++i) {
for (int j = 1; j < i; ++j) {
if (i == cs || i == cf) {
add(f[i][j], f[i - 1][j]);
add(f[i][j + 1], f[i - 1][j]);
} else {
if (j >= 2) add(f[i][j - 1], mul(f[i - 1][j], j - 1));
int k = j - (i > cs) - (i > cf) + 1;
add(f[i][j + 1], mul(f[i - 1][j], k));
}
}
}
cout << f[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... |