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;
using ll = long long;
const int N = 210;
const int MOD = 1e9 + 7;
int grt[N] = {}, sml[N] = {};
ll dp[N][26];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
if(a < b) {
grt[a] = max(grt[a], b);
} else {
sml[b] = max(sml[b], a);
}
}
for(int c = 0; c < 26; c++)
dp[1][c] = 1;
for(int i = 2; i <= n; i++) {
for(int c = 0; c < 26; c++) {
dp[i][c] = 0;
int sm = 0, gr = 0;
for(int k = i - 1; k >= 1; k--) {
sm = max(sm, sml[k]);
gr = max(gr, grt[k]);
if(sm >= i && gr >= i) break;
for(int d = 0; d < 26; d++) {
if(d == c) continue;
if(sm >= i) {
if(d < c) {
dp[i][c] += dp[k][d];
dp[i][c] %= MOD;
}
} else {
if(gr < i || d > c){
dp[i][c] += dp[k][d];
dp[i][c] %= MOD;
}
}
}
}
}
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
for(int c = 0;c < 26; c++) {
ans += dp[i][c];
ans %= MOD;
}
}
cout << ans;
}
# | 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... |