이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int mxn = 205;
const int m = 1e9 + 7;
int dp[mxn][mxn][mxn][2];
// dir : 0 -> left, 1 -> right;
void calc(int sz, int st, int fn, int dir){
if (dp[sz][st][fn][dir] != -1) return;
if (st == fn) {
if (sz == 1) dp[sz][st][fn][dir] = 1;
else dp[sz][st][fn][dir] = 0;
return;
}
dp[sz][st][fn][dir] = 0;
if (dir == 0){
for (int to = 1; to < st; ++to){
if (st < fn) {
calc(sz - 1, to, fn - 1, 1);
dp[sz][st][fn][dir] += dp[sz - 1][to][fn - 1][1];
dp[sz][st][fn][dir] %= m;
}
else {
calc(sz - 1, to, fn, 1);
dp[sz][st][fn][dir] += dp[sz - 1][to][fn][1];
dp[sz][st][fn][dir] %= m;
}
}
} else{
for (int to = st+1; to <= sz; ++to){
if (st < fn) {
calc(sz - 1, to - 1, fn - 1, 0);
dp[sz][st][fn][dir] += dp[sz - 1][to - 1][fn - 1][0];
dp[sz][st][fn][dir] %= m;
}
else {
calc(sz - 1, to - 1, fn, 0);
dp[sz][st][fn][dir] += dp[sz - 1][to - 1][fn][0];
dp[sz][st][fn][dir] %= m;
}
}
}
}
int main() {
int n, cs, cf; cin >> n >> cs >> cf;
memset(dp, -1, sizeof(dp));
calc(n, cs, cf, 0);
calc(n, cs, cf, 1);
int ans = dp[n][cs][cf][0] + dp[n][cs][cf][1];
ans %= m;
cout << ans << "\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... |