另用 乘法逆元(a/b) mod p = (a * b^(p-2)) mod p;
#include<cstdio>
#include<iostream>#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<cstdlib>
#include<map>
#include<cmath>
#include<set>
using namespace std;
const int maxn = 2010;
const long long mo = 1e9 + 7;
struct data{
int x,y;
bool operator < (const data &b) const{
return x < b.x || (x == b.x && y < b.y);
}
}black[maxn];
long long fac[500010],n,m,k,i,j,sum[maxn];
long long mi(long long x,long long y)
{
long long ret = 1;
for (; y; y >>= 1)
{
if (y & 1) ret = ret * x % mo;
x = x * x % mo;
}
return ret;
}
long long C(int x,int y)
{
return fac[x] * mi(fac[y] * fac[x - y] % mo,mo - 2) % mo;
}
int main()
{
#ifndef ONLINE_JUDGE
#ifndef YZY
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#else
freopen("yzy.txt","r",stdin);
#endif
#endif
cin >> n >> m >> k;
fac[0] = 1;
for (i = 1; i <= m + n; i++) fac[i] = fac[i - 1] * i % mo;
for (i = 1; i <= k; i++) scanf("%d%d",&black[i].x,&black[i].y);
black[k + 1].x = n; black[k + 1].y = m;
sort (black + 1,black + k + 2);
for (i = 1; i <= k + 1; i++)
{
int x = black[i].x;
int y = black[i].y;
sum[i] = C(x + y - 2,x - 1);
for (j = 1; j < i; j++)
if (black[j].x <= x && black[j].y <= y)
{
int xx = black[j].x;
int yy = black[j].y;
sum[i] = (sum[i] - sum[j] * C(x + y - xx - yy,x - xx) % mo + mo) % mo;
}
}
cout << sum[k + 1];
return 0;
}