Pagini recente » Cod sursa (job #32128) | Cod sursa (job #3296430) | Cod sursa (job #1206745) | Cod sursa (job #1710690) | Cod sursa (job #1713469)
#include <bits/stdc++.h>
#define maxN 1002
#define maxV 2000002
#define mod 2000003
using namespace std;
int n, m, c, ans, dp[maxN], f[maxV];
struct coord
{
int x, y;
} v[maxN];
int invmod(int x)
{
int i, p = mod - 2, ans = 1, aux = x;
for (i = 1; i <= p; i <<= 1)
{
if(i & p)
ans = (1LL * ans * aux) % mod;
aux = (1LL * aux * aux) % mod;
}
return ans;
}
int C(int x, int y, int z, int t)
{
ans = f[abs(x - z) + abs(y - t)];
ans = (1LL * ans * invmod(f[abs(x - z)])) % mod;
ans = (1LL * ans * invmod(f[abs(y - t)])) % mod;
return ans;
}
int cmp(const coord a, const coord b)
{
if (a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
void read()
{
int i;
freopen("padure2.in", "r", stdin);
scanf("%d %d", &n, &m);
scanf("%d", &c);
for (i = 1; i <= c; ++ i)
scanf("%d %d", &v[i].x, &v[i].y);
f[0] = 1;
for (i = 1; i <= n + m; ++ i)
f[i] = (1LL * f[i - 1] * i) % mod;
}
void solve()
{
int i, j;
sort(v + 1, v + c + 1, cmp);
v[0].x = v[0].y = 1;
for(i = c; i >= 0; -- i)
{
dp[i] = C(n, m, v[i].x, v[i].y);
for(j = i + 1; j <= c; ++ j)
{
if (v[i].y <= v[j].y)
{
dp[i] = dp[i] - (1LL * C(v[i].x, v[i].y, v[j].x, v[j].y) * dp[j]) % mod;
if (dp[i] < 0)
dp[i] += mod;
}
}
}
ans = dp[0];
}
void write()
{
freopen("padure2.out", "w", stdout);
printf("%d\n", ans);
}
int main()
{
read();
solve();
write();
return 0;
}