이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
if (a.empty()) return o << "{}";
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
vv (int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
vv (int n, int m) : vector <vector <T>> (n, vector <T>(m)) {}
vv () {}
};
template <typename T> struct vvv : vector <vv <T>> {
vvv (int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
vvv (int n, int m, int k) : vector <vv <T>> (n, vv <T>(m, k)) {}
vvv () {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 1e9 + 7, N = 202;
void add(int &i, int j) {
i += j;
if (i >= mod)
i -= mod;
}
int dp[N][29];
void solve() {
int n, m;
cin >> n >> m;
vector <vector <int>> adj1(n), adj2(n);
auto add_edge = [&](int u, int v) {
if (u < v)
adj1[u].pb(v);
else
adj2[v].pb(u);
};
for (int i = 0, u, v; i < m; ++i) {
cin >> u >> v, --u, --v;
add_edge(u, v);
}
// s[i - 1] < s[i]
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int c = 0; c < 26; ++c) {
add(dp[i][c + 1], dp[i][c]);
}
// dp[i] -> dp[j];
// s[i - 1] != s[i] -> only care range start from i
// s[j - 1] < s[j]
// no i -> j, i < j
for (int c = 0; c < 26; ++c) {
int mx = 0;
for (int k : adj1[i])
mx = max(mx, k);
for (int j = i + 1; j < n; ++j) {
if (mx < j) {
add(dp[j][c + 1], dp[i][c]);
}
for (int k : adj1[j])
mx = max(mx, k);
}
}
// s[j - 1] > s[j]
// no i -> j, i > j
for (int c = 0; c < 26; ++c) {
int mx = 0;
for (int k : adj2[i])
mx = max(mx, k);
for (int j = i + 1; j < n; ++j) {
if (mx < j) {
add(dp[j][0], dp[i][c]);
add(dp[j][c], mod - dp[i][c]);
}
for (int k : adj2[j])
mx = max(mx, k);
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) for (int c = 0; c < 26; ++c) {
add(ans, dp[i][c]);
}
cout << ans << '\n';
}
int main () {
owo;
int t = 1;
// cin >> t;
while (t--)
solve();
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |