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>
using namespace std;
const int MOD = 1e9 + 7;
int DPplus[41][41][41];
int DPminus[41][41][41];
int main(){
int N, cs, cf; cin >> N >> cs >> cf;
DPplus[2][1][2] = 1LL;
DPminus[2][2][1] = 1LL;
for (int i = 3; i <= 40; i++){
for (int j = 1; j <= i; j++){
for (int k = 1; k <= i; k++){
DPplus[i][j][k] = 0LL;
DPminus[i][j][k] = 0LL;
for (int l = 1; l <= j - 1; l++){
int eps = (k > j);
DPminus[i][j][k] += DPplus[i - 1][l][k - eps];
DPminus[i][j][k] %= MOD;
}
for (int l = j + 1; l <= i; l++){
int eps = (k > j);
DPplus[i][j][k] += DPminus[i - 1][l - 1][k - eps];
DPplus[i][j][k] %= MOD;
}
}
}
}
cout << (DPplus[N][cs][cf] + DPminus[N][cs][cf]) % MOD << endl;
}
# | 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... |