#include <bits/stdc++.h>
using namespace std;
template<typename T> inline void read(T &x){
x = 0; char ch;
while(!isdigit(ch=getchar()));
do{x=10*x+ch-'0';}while(isdigit(ch=getchar()));
}
typedef long long ll;
const int N = 3333;
const ll MOD = 1e9+7;
int row, col, n;
ll F[N][N], Fac[N*N], Finv[N*N], res;
ll power(ll a, int x){
if(x==1) return a;
ll tmp = power(a,x>>1);
tmp = (tmp*tmp)%MOD;
if(x%2) tmp = (tmp*a)%MOD;
return tmp;
}
void init(){
Fac[0] = 1;
for(int i = 1; i <= row*col; i++) Fac[i] = (Fac[i-1]*(ll)i)%MOD;
Finv[0] = 1;
for(int i = 1; i <= row*col; i++){
ll inv = power((ll)i,MOD-2);
Finv[i] = (Finv[i-1]*inv)%MOD;
}
}
ll BC(int k, int n){
return ((Fac[n]*Finv[k])%MOD*Finv[n-k])%MOD;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
read(row); read(col);
init();
read(n);
int u = N, v = N, p = 0, q = 0;
for(int i = 1; i <= n; i++){
int x, y;
read(x); read(y);
u = min(u,x);
v = min(v,y);
p = max(p,x);
q = max(q,x);
}
int x = p-u+1;
int y = q-v+1;
ll need = Fac[x*y-n];
F[row][col] = 1;
for(int i = row; i >= x; i--){
for(int j = col; j >= y; j--){
if(i==row&&j==col) continue;
F[i][j] = (F[i+1][j]*Fac[j]+F[i][j+1]*Fac[i])%MOD;
}
}
res = F[x][y]*BC(u-1,row-x)*BC(v-1,col-y)*need;
cout<<res<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |