Question: Two 01 string s1, s2. each time you change the m position on S1. Ask how many methods can be used to change s1 to S2.
Solution: DP. The key is the state design. It also considers uniqueness and testability. Dp [I] [j] indicates the number of walk methods that are different from the target after step I. Memory-based search dp [0] [dif] (dif indicates the number of different characters at the beginning ). Select an enumeration during transfer.
Code:
/******************************************************* author:xiefubao*******************************************************/#pragma comment(linker, "/STACK:102400000,102400000")#include
#include
#include
#include
#include
#include
#include #include
#include
#include
#include
#include
//freopen ("in.txt" , "r" , stdin);using namespace std;#define eps 1e-8const double pi=acos(-1.0);typedef long long LL;const int Max=110;const int INF=1000000009;int n,k,m;string s1,s2;LL C[Max][Max];int init(){ for(int i=0; i
m) break; ans=(ans+(C[num][i]*C[n-num][m-i])%INF*dfs(step+1,num-i+m-i))%INF; } return dp[step][num]=ans;}int main(){ init(); while(scanf("%d%d%d",&n,&k,&m)==3) { dif=0; memset(dp,-1,sizeof dp); cin>>s1>>s2; for(int i=0; i