https://codeforc.es/gym/102219/problem/F
思路:状态压缩dp;e很小可以压缩;dp[i][j]表示:第i个人和状态j的个数;
#include<algorithm>
#include<set>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-8
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=1e6+9;
const int mod=1e9+7;
inline ll read()
{
ll f=1,x=0;
char ss=getchar();
while(ss<'0'||ss>'9')
{
if(ss=='-')f=-1;ss=getchar();
}
while(ss>='0'&&ss<='9')
{
x=x*10+ss-'0';ss=getchar();
} return f*x;
}
ll power(ll x,ll n)
{
ll ans=1;
while(n)
{
if(n&1) ans=ans*x;
x=x*x;
n>>=1;
}
return ans;
}
ll dp[2009][2009];
bool vis[2009][2009];
int main()
{
//FAST_IO;
int n,e,k;
cin>>n>>e>>k;
for(int i=0;i<k;i++)
{
int u,v;
cin>>u>>v;
vis[u][v]=1;
}
int m=2*e+1;
int s=1<<m;
//cout<<s<<endl;
dp[0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<s;j++)
{
if(!dp[i][j]) continue;
int l=max(1,i-e+1);
int r=min(n,i+e);
int s0=(j<<1);
s0=s0&(s-1);//去掉高位
int p=1;
for(int z=i+e+1;z>r;z--) p<<=1;//去掉i+1的最低位
for(int z=r;z>=l;z--)//从i的最低位开始
{
if(!(s0&p)&&!vis[i+1][z])
{
dp[i+1][s0|p]+=dp[i][j];
dp[i+1][s0|p]%=mod;
}
p<<=1;
}
if(i+e+1<=n&&!vis[i+1][i+e+1])//i+1的最低位
{
dp[i+1][s0|1]+=dp[i][j];
dp[i+1][s0|1]%=mod;
}
}
}
ll ans=0;
for(int i=1;i<s;i++)
{
ans+=dp[n][i];
ans%=mod;
}
cout<<ans<<endl;
return 0;
}