有些点不能走,从1,1走到n,m,每次只能走日字(象棋马),问有多少种走法,
从一个点到指定点的走法可以组合数求解
关于组合数,这篇博客的图很形象http://www.cnblogs.com/hchlqlz-oj-mrj/p/5740838.html
然后排个序容斥掉不能走的点就可以了
#include<bits/stdc++.h>
#define eps 1e-9
#define PI 3.141592653589793
#define bs 1000000007
#define bsize 256
#define MEM(a) memset(a,0,sizeof(a))
typedef long long ll;
using namespace std;
const int mo=110119;
struct node
{
ll x,y;
}num[200];
int cmp(node u,node v)
{
if(u.y==v.y)
return u.x<v.x;
return u.y<v.y;
}
const int N = 210119;
ll fac[N];
ll modpow(ll a, ll b, ll MOD) {
ll ret = 1;
while(b) {
if(b&1) ret = (ret*a)%MOD;
a = (a*a)%MOD;
b>>=1;
}
return ret;
}
ll getFactor(ll p) {
fac[0] = 1;
for(int i = 1; i <= p; i++)
fac[i] = (fac[i-1]*i) % p;
}
ll Lucas(ll n, ll m, ll p) {
if(n<0||m<0||n<m)
return 0;
ll ret=1;
while(n && m) {
ll a = n%p, b = m%p;
if(a<b) return 0;
ret = (ret * fac[a] * modpow(fac[b]*fac[a-b]%p, p-2, p)) % p;
n/=p;
m/=p;
}
return ret;
}
ll f(ll x1,ll y1,ll x2,ll y2)
{
ll x=x2-x1;
ll y=y2-y1;
if(x<0||y<0)
return 0;
ll p=x+y;
if(p%3!=0)
return 0;
p/=3;
return Lucas(p,x-p,mo);
}
ll dp[200];
int main()
{
getFactor(mo);
long long n,m,r,i,j,tca=1;
while(cin>>n>>m>>r)
{
for(i=0;i<r;i++)
cin>>num[i].x>>num[i].y;
num[r].x=n;
num[r].y=m;
r++;
sort(num,num+r,cmp);
for(i=0;i<r;i++)
{
dp[i]=f(1,1,num[i].x,num[i].y);
for(j=0;j<i;j++)
{
dp[i]=(dp[i]-dp[j]*f(num[j].x,num[j].y,num[i].x,num[i].y)%mo+mo)%mo;
}
}
printf("Case #%d: ",tca++);
cout<<dp[r-1]<<endl;
}
return 0;
}