#pragma GCC optimize("O3") #pragma GCC target("avx") #include #define show(x) std::cerr << #x << " = " << (x) << std::endl using ll = long long; constexpr ll MOD = 100000007; template class ModCombination { public: ModCombination(const std::size_t n) : fact(n + 1, 1), inv(n + 1, 1), inv_fact(n + 1, 1) { for (ll i = 2; i <= (ll)n; i++) { fact[i] = (fact[i - 1] * i) % mod, inv[i] = ((mod - (mod / i)) * inv[mod % i]) % mod, inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod; } } ll combination(const std::size_t n, const std::size_t k) const { return (((fact[n] * inv_fact[k]) % mod) * inv_fact[n - k]) % mod; } private: std::vector fact, inv, inv_fact; }; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int H, W, K; std::cin >> H >> W >> K; ModCombination<> mod(H + W); std::vector a(K + 2), b(K + 2); a[0] = b[0] = 0, a[K + 1] = H, b[K + 1] = W; for (int i = 1; i <= K; i++) { std::cin >> a[i] >> b[i]; } std::vector> d(K + 2, std::vector(K + 2, 0)); for (int i = 0; i < K + 2; i++) { for (int j = 0; j < K + 2; j++) { if (a[i] <= a[j] and b[i] <= b[j]) { d[i][j] = mod.combination(a[j] + b[j] - a[i] - b[i], a[j] - a[i]); } } } std::vector> memo1(K + 2, std::vector(K + 2, -1)); auto dp1 = [&](auto&& self, const int s, const int g) -> ll { if (memo1[s][g] != -1) { return memo1[s][g]; } ll ans = d[s][g]; for (int i = 1; i <= K; i++) { if (i == s or i == g or d[i][g] == 0) { continue; } const ll minus = self(self, s, i) * d[i][g] % MOD; (ans += (MOD - minus)) %= MOD; } return memo1[s][g] = ans; }; std::vector memo2(K + 2, -1); for (int q = 0; q < (1 << K); q++) { auto at = [&](const int j) -> bool { return (q >> j) & 1; }; std::fill(memo2.begin(), memo2.end(), -1); auto dp2 = [&](auto&& self, const int s) { if (memo2[s] != -1) { return memo2[s]; } ll ans = dp1(dp1, s, K + 1); for (int i = 1; i <= K; i++) { if (s == i or d[s][i] == 0 or at(i - 1)) { continue; } (ans += dp1(dp1, s, i) * self(self, i) % MOD) %= MOD; } return memo2[s] = ans; }; std::cout << dp2(dp2, 0) << "\n"; } return 0; }