to two long n 01 strings of S1 and S2, to the S1 to make a K-change, each change m different positions, asked several ways to modify the S2.
Want to offset, only think of the original 01 value is not important, because the parity of the number of changes in each location is determined by this layer.
In fact, this problem as long as the concern from the beginning to the end of a few positions are different, a value is sufficient.
Then the specific state is: Dp[i][j], after I have been modified there are different number of J positions.
Transfer with me for everyone, dp[i][j] by selecting Modify a position different, m-a position the same transfer to dp[i+1][j-(A-(m-a))], i.e. dp[i+1][j-(A-(m-a))]=∑c (j,a) *c (n-j,m-a) *dp[i][j].
The design and transfer of the state of the problem is quite a coincidence for me.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Long Longd[111][111],c[111][111];6 intMain () {7 for(intI=0; i<111; ++i) c[i][0]=1;8 for(intI=1; i<111; ++i) {9 for(intj=1; j<=i; ++J) c[i][j]= (c[i-1][j-1]+c[i-1][J])%1000000009;Ten } One Chars1[111],s2[111]; A intn,k,m; - while(~SCANF ("%d%d%d",&n,&k,&m)) { -scanf"%s%s", S1,S2); the intCnt=0; - for(intI=0; i<n; ++i) { - if(S1[i]!=s2[i]) + +CNT; - } +memset (D,0,sizeof(d)); -d[0][cnt]=1; + for(intI=0; i<k; ++i) { A for(intj=0; j<=n; ++j) { at if(d[i][j]==0)Continue; - for(intk=0; k<=j; ++k) { - if(J (K-(m-k)) <0|| n-j<0|| m-k<0)Continue; -d[i+1][j-(k (m-k))]+=c[j][k]*c[n-j][m-k]%1000000009*d[i][j]%1000000009; -d[i+1][j-(k (m-k))]%=1000000009; - } in } - } toprintf"%lld\n", d[k][0]); + } - return 0; the}
ZOJ3791 an easy Game (DP)