An Easy Game


Time Limit: 2 Seconds      Memory Limit: 65536 KB

One day, Edward and Flandre play a game. Flandre will show two 01-strings s1 and s2, the lengths of two strings are n. Then, Edward must move exact k steps. In each step, Edward should change exact m positions of s1. That means exact m positions of s1, '0' will be changed to '1' and '1' will be changed to '0'.

The problem comes, how many different ways can Edward change s1 to s2 after k steps? Please calculate the number of the ways mod 1000000009.

Input

Input will consist of multiple test cases and each case will consist of three lines. The first line of each case consist of three integers n (1 ≤ n ≤ 100), k (0 ≤ k ≤ 100), m (0 ≤ mn). The second line of each case is a 01-string s1. The third line of each case is a 01-string s2.

Output

For each test case, you should output a line consist of the result.

Sample Input

3 2 1
100
001

Sample Output

2

Hint

100->101->001
100->000->001

题目大意:给两个01字符串s1,s2,经过K次操作每次对M个取反,求有多少种方案使得s1==s2。 dp[i][j]表示i次操作之后有j个位置不同的方法数,答案就是dp[t][0]。对于dp[i - 1][j],经过一次操作之后假设把t个位置从不同变为相同,剩下m - t个位置从相同变为不同。
那么
dp[i][j + m - t - t] += dp[i - 1][j] * C(j, t) * C(n - j, m - t)


 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; typedef __int64 LL;
const int maxn=;
const int Mod=;
int n,k,m,C[maxn][maxn];
LL d[maxn][maxn];
char s1[maxn],s2[maxn]; int max(int a,int b){return a>b?a:b;} void init_C()
{
memset(C,,sizeof(C));
int i,j;
for(i=;i<=;i++)
{
C[i][]=;
for(j=;j<=i;j++)
{
C[i][j]=(C[i-][j-]+C[i-][j])%Mod;
}
}
} void solve()
{
memset(d,,sizeof(d));
int i,j,t,dif=;
for(i=;i<n;i++) dif+=(s1[i]!=s2[i]?:);
d[][dif]=;
for(i=;i<=k;i++)
{
for(j=;j<=n;j++)
{
for(t=max(,m-(n-j));t<=j && t<=m;t++)
{
d[i][j+m-t-t]=(d[i][j+m-t-t]+d[i-][j]*C[j][t]%Mod*C[n-j][m-t]%Mod)%Mod;
}
}
}
printf("%I64d\n",d[k][]);
}
int main()
{
init_C();
while(~scanf("%d %d %d",&n,&k,&m))
{
getchar();
gets(s1);
gets(s2);
solve();
}
return ;
}

												

zoj 3791 An Easy Game dp的更多相关文章

  1. ZOJ 3791 An easy game DP+组合数

    给定两个01序列,每次操作可以任意改变其中的m个数字 0变 1  1 变 0,正好要变化k次,问有多少种变法 dp模型为dp[i][j],表示进行到第i次变化,A,B序列有j个不同的 变法总和. 循环 ...

  2. ZOJ 3791 An Easy Game(DP)

    题目链接 题意 : 给你两个长度为N的字符串,将第一个字符串每次只能变化M个,问变换K次之后变成第二个字符串一共有几种方法. 思路 : DP.dp[i][j]表示变了 i 次之后有j个不一样的字母的方 ...

  3. ZOJ 3791 An Easy Game

     思路:dp+记忆化搜索,设dp[n][m]表示s1与s2不同字符个数为n,还需要变m步的方法数,那么: dp[n][m]  = (c[n][i]*c[N-n][K-i]) * dp[n-i+(K-i ...

  4. 2014 Super Training #8 C An Easy Game --DP

    原题:ZOJ 3791 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3791 题意:给定两个0-1序列s1, s2,操作t ...

  5. HDU 4359——Easy Tree DP?——————【dp+组合计数】

    Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  6. HDU 4359 Easy Tree DP?

    Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )

    D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...

  8. leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution)

    leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution) On a staircase, the i-th step ...

  9. [ZOJ]3541 Last Puzzle (区间DP)

    ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...

随机推荐

  1. Java多线程 编写三各类Ticket、SaleWindow、TicketSaleCenter分别代表票信息、售票窗口、售票中心。 售票中心分配一定数量的票,由若干个售票窗口进行出售,利用你所学的线程知识来模拟此售票过程。

    package com.swift; import java.util.ArrayList; import java.util.HashMap; import java.util.List; impo ...

  2. ios下通过webservice获取数据

    经历了两天的摸索,终于成功获取了数据,因为公司要做一个停车入库的信息查询,所以需要访问webservice的接口,由于没有接触过webservice,所以第一天就是各种搜索资料,类库,各种尝试,甚至是 ...

  3. (2) html 语义化

    HTML语义化标签 1 什么是语义化标签? 通过标签判断内容语义,例如根据h1标签判断出内容是标题,根据 p 判断内容是段落.input 标签是输入框等. 2 为什么要标签语义化? 1.搜素引擎友好 ...

  4. 洛谷 P5016 龙虎斗

    输入兵营总数.兵营人数.以m分界. 然后输入s1个兵到了p1兵营. 最终我们要求的是把s2个兵放到哪个兵营使龙虎双方气势差距最小. 第一要把每个兵营的气势算出来,并且加到它所属的阵营里(<m是龙 ...

  5. Bootstrap 模态框 select2搜索框无法输入

    去掉模态框的div中的 tabindex="-1" 这个属性 <div class="modal fade" role="dialog" ...

  6. Golang ioutil读写文件测试

    运用 ioutil.ReadFile .ioutil.WriteFile package main import ( "io/ioutil" "log" &qu ...

  7. 使用jquery清除select中的所有option

    html代码 <select id="search"> <option>baidu</option> <option>sogou&l ...

  8. ASP( VBScript ) 解析 JSON

    <script language="jscript" runat="server"> Array.prototype.get = function( ...

  9. Python简单试题2

    1,给定一组数据,将奇数进行从小到大排序,偶数在原位置不变 例: 原数据:[5, 3, 2, 8, 1, 4]   排序后:[5, 3, 2, 8, 1, 4] 若数组为空,则返回空数组. 代码如下: ...

  10. Python之路-时间模块

    time模块 import time 时间戳(time.time())--结构化时间(time.localtime)--字符串时间(time.strftime) import time print(t ...