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 <iostream>
#include <sstream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 210 + 37;
const int mod = 1e9 + 7;
ll dp[maxn][maxn][maxn][3], par[maxn][maxn][maxn][3];
int main() {
ios_base::sync_with_stdio(false);
int n, s, t;
cin >> n >> s >> t;
dp[2][1][2][1] = 1;
dp[2][2][1][0] = 1;
par[2][1][2][1] = 1;
par[2][2][2][1] = 1;
par[2][2][1][0] = 1;
for (int i = 3; i <= n; i++) {
for (int st = 1; st <= i; st ++) {
for (int en = 1; en <= i; en ++) {
if (st != en) {
if (en > st) {
dp[i][st][en][1] = (dp[i][st][en][1] + par[i - 1][i - 1][en - 1][0] - par[i - 1][st - 1][en - 1][0] + mod + mod) % mod;
dp[i][st][en][0] = (dp[i][st][en][0] + par[i - 1][st - 1][en - 1][1]) % mod;
}
else {
dp[i][st][en][1] = (dp[i][st][en][1] + par[i - 1][i - 1][en][0] - par[i - 1][st - 1][en][0] + mod + mod) % mod;
dp[i][st][en][0] = (dp[i][st][en][0] + par[i - 1][st - 1][en][1] + mod) % mod;
}
// cout << i << " " << st << " " << en << " right " << dp[i][st][en][1] << endl;
// cout << i << " " << st << " " << en << " left " << dp[i][st][en][0] << endl;
}
par[i][st][en][1] = (par[i][st - 1][en][1] + dp[i][st][en][1]) % mod;
par[i][st][en][0] = (par[i][st - 1][en][0] + dp[i][st][en][0]) % mod;
}
}
}
cout << (dp[n][s][t][1] + dp[n][s][t][0]) % 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... |