One day, Edward and Flandre play a game. Flandre will show two 01-strings s1 and s2, the lengths of two strings are n. Then, Edward must move exact k steps. In each step, Edward should change exact m positions of s1. That means exact m positions of s1, '0' will be changed to '1' and '1' will be changed to '0'.
The problem comes, how many different ways can Edward change s1 to s2 after k steps? Please calculate the number of the ways mod 1000000009.
Input
Input will consist of multiple test cases and each case will consist of three lines. The first line of each case consist of three integers n (1 ≤ n ≤ 100), k (0 ≤ k ≤ 100), m (0 ≤ m ≤ n). The second line of each case is a 01-string s1. The third line of each case is a 01-string s2.
Output
For each test case, you should output a line consist of the result.
Sample Input
3 2 1 100 001
Sample Output
2
Hint
100->101->001 100->000->001
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const long long int MOD = 1000000009LL;
long long C[110][110],dp[110][110];
int n,m,K;
char s1[110],s2[110];
int main()
{
for(int i=0;i<110;i++) C[i][i]=1LL,C[i][0]=1LL;
for(int i=2;i<110;i++) for(int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
while(scanf("%d%d%d",&n,&m,&K)!=EOF)
{
memset(dp,0,sizeof(dp));
scanf("%s%s",s1,s2);
int nt=0;
for(int i=0;i<n;i++)
if(s1[i]!=s2[i]) nt++;
dp[0][nt]=1;
for(int i=1;i<=m;i++)
{
for(int j=0;j<=n;j++)
{
for(int k=max(0,j-K);k<=min(n,j+K);k++)
{
/// dp[i][j]+=dp[i-1][k]*C[][]*C[][];
int deta=j-k;///不同的位置个数变化量
if(deta>=0)
{
if(deta==K||(K-deta)%2==0)
{
dp[i][j]=(dp[i][j]+((dp[i-1][k]*C[k][(K-deta)/2])%MOD*C[n-k][deta+(K-deta)/2])%MOD)%MOD;
}
}
else if(deta<0)
{
deta*=-1;
if(deta==K||(K-deta)%2==0)
{
dp[i][j]=(dp[i][j]+((dp[i-1][k]*C[k][deta+(K-deta)/2])%MOD*C[n-k][(K-deta)/2])%MOD)%MOD;
}
}
}
}
}
printf("%lld\n",dp[m][0]);
}
return 0;
}