1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <vector> 6 #include <map> 7 #define MP make_pair 8 using namespace std; 9 10 typedef long long LL; 11 12 const int maxn = 80; 13 14 int n, k; 15 16 vector<int> G[maxn], req[maxn]; 17 18 LL d[maxn][maxn]; 19 20 bool check(int L, int R, int l, int r) 21 { 22 for(int i = 0; i < G[l].size(); i++) 23 { 24 int v = G[l][i], t = req[l][i]; 25 if(t == -2) 26 { 27 if(v < L || v > R || v == r) return false; 28 } 29 else if(t == -1) 30 { 31 if(v < L || v > R) return false; 32 } 33 else if(!t) 34 { 35 if(v != r) return false; 36 } 37 else if(t == 1) 38 { 39 if(v >= L && v <= R && v != r) return false; 40 } 41 else 42 { 43 if(v >= L && v <= R) return false; 44 } 45 } 46 47 for(int i = 0; i < G[r].size(); i++) 48 { 49 int v = G[r][i], t = req[r][i]; 50 if(t == -2) 51 { 52 if(v < L || v > R || v == l) return false; 53 } 54 else if(t == -1) 55 { 56 if(v < L || v > R) return false; 57 } 58 else if(!t) 59 { 60 if(v != l) return false; 61 } 62 else if(t == 1) 63 { 64 if(v >= L && v <= R && v != l) return false; 65 } 66 else 67 { 68 if(v >= L && v <= R) return false; 69 } 70 } 71 72 return true; 73 } 74 75 LL dp(int L, int R) 76 { 77 LL& ans = d[L][R]; 78 if(ans >= 0) return d[L][R]; 79 if(L + 1 == R) 80 { 81 if(check(L, R, L, R)) return 1LL; 82 return 0; 83 } 84 85 ans = 0; 86 87 if(check(L, R, L, L + 1)) 88 ans += dp(L + 2, R); 89 if(check(L, R, L, R)) 90 ans += dp(L + 1, R - 1); 91 if(check(L, R, R - 1, R)) 92 ans += dp(L, R - 2); 93 94 return ans; 95 } 96 97 int main() 98 { 99 scanf("%d%d", &n, &k); 100 char eq[10]; 101 while(k--) 102 { 103 int u, v; 104 scanf("%d", &u); 105 scanf("%s", eq); 106 scanf("%d", &v); 107 108 int t; 109 if(strcmp(eq, "<") == 0) t = -2; 110 else if(strcmp(eq, "<=") == 0) t = -1; 111 else if(strcmp(eq, "=") == 0) t = 0; 112 else if(strcmp(eq, ">=") == 0) t = 1; 113 else if(strcmp(eq, ">") == 0) t = 2; 114 else exit(1234); 115 116 if(u == v) 117 { 118 if(abs(t) <= 1) continue; 119 else { puts("0"); exit(0); } 120 } 121 122 req[u].push_back(t); req[v].push_back(-t); 123 G[u].push_back(v); G[v].push_back(u); 124 } 125 126 memset(d, -1, sizeof(d)); 127 128 printf("%I64d\n", dp(1, n * 2)); 129 130 return 0; 131 }
代码君
时间: 2024-10-15 15:53:32