Pagini recente » Cod sursa (job #1704467) | Cod sursa (job #2800045) | Cod sursa (job #147795) | Cod sursa (job #1151230) | Cod sursa (job #1710685)
/**
* Code by Patrick Sava
* "Spiru Haret" National College of Bucharest
**/
# include "fstream"
# include "cstring"
# include "vector"
# include "queue"
# include "bitset"
# include "algorithm"
# include "map"
# include "unordered_map"
# include "deque"
# include "string"
# include "iomanip"
# include "cmath"
# include "stack"
# include "cassert"
const char IN [ ] = "padure2.in" ;
const char OUT [ ] = "padure2.out" ;
const int MAX = 1014 ;
const int MOD = 2000003 ;
# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )
using namespace std ;
ifstream cin ( IN ) ;
ofstream cout ( OUT ) ;
int dp [ MAX ] ;
pair < int , int > points [ MAX ] ;
int fact [ MOD ] ;
int put ( int x , int y ) {
int ret = 1 ;
for ( ; y ; y >>= 1 ) {
if ( y & 1 ) {
ret = 1LL * ret * x % MOD ;
}
x = 1LL * x * x % MOD ;
}
return ret ;
}
int comb ( int x , int y ) {
if ( x == y or y == 0 ) {
return 1 ;
}
int aux1 = put ( fact [y] , MOD - 2 ) ;
int aux2 = put ( fact [x - y], MOD - 2 ) ;
int aux3 = 1LL * aux1 * aux2 % MOD ;
return 1LL * fact [ x ] * aux3 % MOD ;
}
int main()
{
fact [ 0 ] = 1 ;
int n , m ;
cin >> n >> m ;
int lim = n + m ;
FORN ( i , 1 , lim ) {
fact [ i ] = 1LL * fact [ i - 1 ] * i % MOD ;
}
int k ;
cin >> k ;
FORN ( i , 1 , k ) {
int x , y ;
cin >> x >> y ;
points [ i ] = mp ( x , y ) ;
}
sort ( points + 1 , points + k + 1 ) ;
FORN ( i , 1 , k ) {
dp [ i ] = comb ( points [ i ].first + points [ i ].second - 2 , points [ i ].first - 1 ) ;
FORNBACK ( j , i - 1 , 1 ) {
if ( points [ j ].second <= points [ i ].second ) {
dp [ i ] -= dp [ j ] ;
if ( dp [ i ] < 0 ) {
dp [ i ] += MOD ;
}
}
}
}
int total = comb ( n + m - 2 , m - 1 ) ;
FORN ( i , 1 , k ) {
int x = n - points [ i ].first + 1 ;
int y = m - points [ i ].second + 1 ;
int aux = comb ( x + y - 2 , y - 1 ) ;
int prod = 1LL * aux * dp [ i ] % MOD ;
total -= prod ;
if ( total < 0 ) {
total += MOD ;
}
}
cout << total << '\n' ;
return 0;
}