#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int N=2010,P=1000000007;
void upd(LL &x,LL y){x=(x+y)%P;}
int n,m,p;
LL f[N][N],g[N][N],ans;
bool equ(int a,int b){
if ((a==0)^(b==0)) return 0;
a=(a-1)%(p-1)+1;
b=(b-1)%(p-1)+1;
return a==b;
}
int main(){
// freopen("t.txt","r",stdin);
scanf("%d%d%d",&n,&m,&p);
int len=(n+m-1)/(p-1);
f[0][0]=1;
rep(i,1,len) rep(j,0,n){
rep(k,0,p-1){
if (j<k) continue;
upd(f[i][j],f[i-1][j-k]);
}
rep(k,1,p-1){
if (j<k) continue;
upd(g[i][j],f[i-1][j-k]);
}
int x=j,y=i*(p-1)-j+1;
if (equ(x,n)&&equ(y,m)&&y<=m){
upd(ans,g[i][j]);
// printf("ans=%lld ,from g[%d][%d]=%lld\n",ans,i,j,g[i][j]);
}
}
printf("%lld\n",ans);
return 0;
}
./Main.cpp: In function ‘int main()’:
./Main.cpp:24:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&n,&m,&p);
^