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

 

posted @ 2014-06-21 18:40  null1019  阅读(226)  评论(0编辑  收藏  举报