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;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int maxn = 200;
const int mod = 1e9 + 7;
const int k = 26;
int n, m;
vector<int> ups[1 + maxn];
vector<int> downs[1 + maxn];
int up[1 + maxn];
int down[1 + maxn];
bool hasup[1 + maxn][1 + maxn];
bool hasdown[1 + maxn][1 + maxn];
int dp[1 + maxn][1 + maxn][k];
void solve() {
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
if(a < b) {
downs[a].pb(b);
} else {
ups[b].pb(a);
}
}
for(int i = 1; i <= n; i++) {
for(int j : ups[i]) {
up[i] = max(up[i], j);
}
for(int j : downs[i]) {
down[i] = max(down[i], j);
}
}
for(int idx = 1; idx <= n; idx++) {
if(up[idx] != 0) {
for(int j = 1; j <= idx; j++) {
for(int i = idx; i < up[idx]; i++) {
hasup[i][j] = true;
}
}
}
if(down[idx] != 0) {
for(int j = 1; j <= idx; j++) {
for(int i = idx; i < down[idx]; i++) {
hasdown[i][j] = true;
}
}
}
}
for(int c = 0; c < k; c++) {
dp[1][1][c] = 1;
}
for(int i = 1; i < n; i++) {
for(int j = 1; j <= i; j++) {
for(int c = 0; c < k; c++) {
dp[i + 1][j][c] += dp[i][j][c];
dp[i + 1][j][c] %= mod;
if(!hasup[i][j]) {
// can go down
for(int d = 0; d < c; d++) {
dp[i + 1][i + 1][d] += dp[i][j][c];
dp[i + 1][i + 1][d] %= mod;
}
}
if(!hasdown[i][j]) {
// can go up
for(int d = c + 1; d < k; d++) {
dp[i + 1][i + 1][d] += dp[i][j][c];
dp[i + 1][i + 1][d] %= mod;
}
}
}
}
}
int ans = 0;
for(int j = 1; j <= n; j++) {
for(int c = 0; c < k; c++) {
ans += dp[n][j][c];
ans %= mod;
}
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
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... |