![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define int long long #define mod 1000000007 using namespace std; inline int read(){ int f=1,ans=0;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();} return f*ans; } const int N=200011; int inv[N],fac[N]; int ksm(int a,int b){ int ans=1; while(b){ if(b&1) ans*=a,ans%=mod; a*=a,a%=mod; b>>=1; }return ans%mod; } int n,m,k; struct node{ int x,y; }a[N]; int C(int m,int n){if(n==0) return 1;return (fac[m]*((inv[n]*inv[m-n])%mod))%mod;} bool cmp(node x1,node x2){ if(x1.x==x2.x) return x1.y<x2.y; return x1.x<x2.x; } int f[N]; signed main(){ inv[0]=1,fac[0]=1; for(int i=1;i<=200001;i++){ fac[i]=(fac[i-1]*i)%mod; inv[i]=ksm(fac[i],mod-2); } n=read(),m=read(),k=read(); for(int i=1;i<=k;i++) a[i].x=read(),a[i].y=read(); sort(a+1,a+k+1,cmp); a[++k].x=n,a[k].y=m; for(int i=1;i<=k;i++){ f[i]=C(a[i].x+a[i].y-2,a[i].x-1)%mod; for(int j=1;j<i;j++){ if(a[j].x>a[i].x||a[j].y>a[i].y) continue; f[i]-=f[j]*C(a[i].x-a[j].x+a[i].y-a[j].y,a[i].x-a[j].x); f[i]=((f[i]%mod)+mod)%mod; } } printf("%lld",(f[k]%mod+2*mod)%mod); }