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. 数据库-SQL语法:把一个字段的值设为随机整数

     update test2 set zuig = (cast ( ceiling (rand()*9) as int))  

  2. 【转】JavaScript 节点操作 以及DOMDocument属性和方法

    最近发现DOMDocument对象很重要,还有XMLHTTP也很重要 注意大小写一定不能弄错. 属性: 1Attributes 存储节点的属性列表(只读) 2childNodes 存储节点的子节点列表 ...

  3. ValidForm验证表单

    在做项目时,要求熟悉项目中验证表单的插件,所以学习一下validForm这个插件 http://validform.rjboy.cn/document.html#validformObject

  4. Find the Longest Word in a String-freecodecamp算法题目

    Find the Longest Word in a String(找出最长单词) 要求 在句子中找出最长的单词,并返回它的长度 函数的返回值应该是一个数字. 思路 用.split(' ')将句子分隔 ...

  5. 【转】再谈 最速下降法/梯度法/Steepest Descent

    转载请注明出处:http://www.codelast.com/ 最速下降法(又称梯度法,或Steepest Descent),是无约束最优化领域中最简单的算法,单独就这种算法来看,属于早就“过时”了 ...

  6. kmp和hash 字符串处理 哈希表

    来自http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html 并进行自己的简单整 ...

  7. 关于bc中小数点length,scale,(())以及进制转换

    这是我在codewar上遇到的一个题,我用我自己的方法做出了解答,如下: 1 #!/bin/bash 2 3 distance=`echo "$1*10000"|bc|cut -d ...

  8. Vue 父子组件间的通信

    前言 在 Vue 项目中父子组件的通信是非常常见的,最近做项目的时候发现对这方面的知识还不怎么熟练,在这边做一下笔记,系统学习一下吧. 1 父组件传值给子组件 1.1 传值写法 父组件传值给子组件,这 ...

  9. 掌握这些Python代码技巧,编程至少快一半!

    被人工智能捧红的 Python 已是一种发展完善且非常多样化的语言,其中肯定有一些你尚未发现的功能.本文或许能够让你学到一些新技巧. ​ Python 是世界上最流行.热门的编程语言之一,原因很多,比 ...

  10. 【原创】关于高版本poi autoSizeColumn方法异常的情况

    之前使用的3.9版本,autoSizeColumn方法一切正常,现在切换到了3.15版本这个方法就出先了问题,问题如下,无法自动追踪所有的列. Exception in thread "ma ...