Pagini recente » Cod sursa (job #2038161) | Cod sursa (job #1112038) | Clasament laborator2_10i | Cod sursa (job #1070047) | Cod sursa (job #1928906)
#include<bits/stdc++.h>
using namespace std;
typedef struct lol {
int x, y;
friend bool operator < (const lol &a, const lol &b) {
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
}troll;
const int MOD = 2000003;
int i, j, fact[2000005], n, m, k, dp[1005], aux;
troll p[1005];
long long Pow(long long a, int b) {
long long ans = 1;
while(b)
if(b & 1) ans *= a, ans %= MOD, --b;
else a *= a, a %= MOD, b /= 2;
return ans;
}
int comb(int n, int k) {
if(n < k || n < 0 || k < 0 || !n) return 0;
int ans = (1LL * fact[n] * Pow(fact[k], MOD - 2)) % MOD;
return (1LL * ans * Pow(fact[n - k], MOD - 2)) % MOD;
}
int main() {
ifstream cin("padure2.in");
ofstream cout("padure2.out");
ios_base::sync_with_stdio(0);
for(i = fact[0] = 1; i <= 2e6; ++i) fact[i] = (1LL * fact[i - 1] * i) % MOD;
cin >> n >> m >> k;
for(i = 1; i <= k; ++i) cin >> p[i].x >> p[i].y;
sort(p + 1, p + k + 1);
if(p[k].x == n && p[k].y == m) return cout << "0\n", 0;
p[++k].x = n; p[k].y = m;
for(i = 1; i <= k; ++i) {
dp[i] = comb(p[i].x + p[i].y - 2, p[i].x - 1);
for(j = i - 1; j; --j) {
if(p[i].y < p[j].y) continue;
int lenx = abs(p[i].x - p[j].x + 1);
int leny = abs(p[i].y - p[j].y + 1);
aux = (1LL * dp[j] * comb(lenx + leny - 2, lenx - 1)) % MOD;
dp[i] -= aux;
if(dp[i] < 0) dp[i] += MOD;
}
}
cout << dp[k] << '\n';
return 0;
}