Zoj1_1 (An Easy Game) DP

Source: Internet
Author: User

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
             
              

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.