"Problem description"

Oi Master shook son after winning the silver medal, smooth walk PKU. This day, trembling son asked the elder: "Although I have been a walk, but I have to participate in the study exam." Soon to test the political, how should I learn philosophy, pass the political examination? ”

The elder replied: "You ah, Tooyoung Too simple,sometimes naive! philosophy This kind of thing, not to say want to understand can understand, need meditation tear roast." You go to the forest in the back and think about it. ”

The elder's backyard has a zhe ♂ learn forest. For some mysterious reasons, the forest forms a n*m rectangle, where each point represents a tree. In addition, some of the trees were uprooted (i.e. disappeared) because of the kjdh of the spicy chicken. Shaking every day to the tree to rip the roast, so he wants to choose a tree in each row. But he hated going backwards, so the tree I chose for row I had to be on the right side of line i-1. Now I want to know how many options there are in total.

"Input Format"

The first row of three integer n,m,p, representing the length and width of the forest, and the number of trees that have disappeared.

The next P line is two integers per line, indicating that the tree of the first AI row bi column disappears.

p<=2000 n,m<=10^9

"Output Format"

An integer line that represents the number of scenarios. Because the answer may be large, please take a 1000003 modulo.

Exercises

C (n,m)%p=c (n%p,m%p) *c (n/p,m/p)%p

Obviously down x units, right y scheme is C (x-1,y-1)

F[i] only to the first I point of the scheme number

F[i]=c (x[i]-1,y[i]-1)-sigma (F[j]*c (x[i]-x[j]-1,y[i]-y[j]-1)) (y[i]>=y[j]&&x[i]>=x[j]&&i >J)

#include <stdio.h>#include<stdlib.h>#include<iostream>#include<string>#include<string.h>#include<algorithm>#include<math.h>#include<queue>#include<map>#include<vector>#include<Set>#defineIl inline#defineRe Register#defineMoD 1000003using namespaceStd;typedefLong Longll;Const intn= .;intn,a[1100000],r[1100000],m,p,f[n];structdata{intx, y;} T[n];ilBOOLCMP (data a,data b) {returna.x<b.x;} IlintCintNintm) { if(n<m)return 0; if(N<mod)return1ll*a[n]*r[m]*r[n-m]%MoD; return1ll*c (N/mod,m/mod) *c (n%mod,m%mod)%MoD;}intMain () {Freopen ("zhexue.in","R", stdin); Freopen ("Zhexue.out","W", stdout); a[0]=1; r[1]=1; r[0]=1; for(intI=1; i<mod;i++) a[i]=1ll*a[i-1]*i%MoD; for(intI=2; i<mod;i++) r[i]=1ll*r[mod%i]* (mod-mod/i)%MoD; for(intI=1; i<mod;i++) r[i]=1ll*r[i]*r[i-1]%MoD; scanf ("%d%d%d",&n,&m,&p); for(intI=1; i<=p;i++) scanf ("%d%d",&t[i].x,&t[i].y); t[++p].x=n+1; t[p].y=m+1; Sort (T+1, t+p+1, CMP); for(intI=1; i<=p;i++) {F[i]=c (t[i].y-1, t[i].x-1); //cout<<f[i]<<endl; for(intj=1; j<i;j++) if(t[j].x<t[i].x&&t[j].y<t[i].y) {F[i]= ((F[i]-1ll*f[j]*c (t[i].y-t[j].y-1, t[i].x-t[j].x-1)%mod)%mod+mod)%MoD; }} cout<<F[p]; return 0;}

"Algorithm" Lucas theorem