zoj 3791 An Easy Game
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                zoj 3791 An Easy Game
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3791
題目大意:給你兩個長度為n的01串,第一個為起始串,另一個為目標串。給你k次操作,每次選擇起始串的m個不同的位置取反(0變1,1變0),問k次操作以后有多少種方案能使得起始串變成目標串。
dp[i][j]表示第i步后有就j個不匹配的步數。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define ll long long 5 #define maxn 200 6 using namespace std; 7 const int mod=1e9+9; 8 9 ll c[maxn][maxn],dp[maxn][maxn]; 10 int n,k,m; 11 char str1[maxn],str2[maxn]; 12 13 void get() 14 { 15 for(int i=0; i<maxn; i++) c[i][0]=1; 16 for(int i=1; i<maxn; i++) 17 { 18 for(int j=1; j<=i; j++) 19 { 20 c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod; 21 } 22 } 23 } 24 25 int main() 26 { 27 get(); 28 while(scanf("%d%d%d",&n,&k,&m)!=EOF) 29 { 30 scanf("%s",str1); 31 scanf("%s",str2); 32 int cnt=0; 33 for(int i=0; i<n; i++) 34 { 35 if(str1[i]!=str2[i]) cnt++; 36 } 37 memset(dp,0,sizeof(dp)); 38 dp[0][cnt]=1; 39 for(int i=0; i<k; i++) 40 { 41 for(int j=0; j<=n; j++) 42 { 43 for(int x=0; x<=m; x++) 44 { 45 if(j+m-2*x<0) break; 46 if(j+m-2*x>n) continue; 47 dp[i+1][j+m-2*x]=(dp[i+1][j+m-2*x]%mod+c[j][x]*c[n-j][m-x]%mod*dp[i][j]%mod)%mod; 48 } 49 } 50 } 51 printf("%lld\n",dp[k][0]); 52 } 53 return 0; 54 } View Code?
轉載于:https://www.cnblogs.com/fanminghui/p/3801290.html
總結
以上是生活随笔為你收集整理的zoj 3791 An Easy Game的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Leetcode Combination
 - 下一篇: 好东西分享兼备忘