思路:dp+记忆化搜索,设dp[n][m]表示s1与s2不同字符个数为n,还需要变m步的方法数,那么:

dp[n][m]  = (c[n][i]*c[N-n][K-i]) * dp[n-i+(K-i)][m-1]  (i需满足数组下标不小0)。c数组表示组合数。

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MOD 1000000009
const int MAXN = 101;
using namespace std;
long long int dp[MAXN][MAXN], c[MAXN][MAXN], N, M, K;
void init(){
c[0][0] = 1, c[1][0] = 1, c[1][1] = 1;
for(int i = 2; i < MAXN; i ++){
c[i][0] = 1;
for(int j = 1; j <= i; j ++){
c[i][j] = c[i-1][j-1] + c[i-1][j];
if(c[i][j] >= MOD) c[i][j] %= MOD;
}
}
}
int dfs(int n, int m){
if(dp[n][m] != -1) return dp[n][m];
if(m == 0) return dp[n][m] = (n == 0);
dp[n][m] = 0;
for(int i = 0; i <= K; i ++){
if(n < i || N - n < K - i) continue;
dp[n][m] += (((c[n][i] * c[N-n][K-i]) % MOD) * dfs(n - i + (K - i), m-1))%MOD;
dp[n][m] %= MOD;
}
return dp[n][m];
}
int main(){
string s1, s2;
init();
while(cin >> N >> M >> K){
cin >> s1 >> s2;
int cnt = 0;
for(int i = 0; i < N; i ++)
if(s1[i] != s2[i]) cnt ++;
memset(dp, -1, sizeof dp);
printf("%d\n", dfs(cnt, M));
}
return 0;
}



ZOJ 3791 An Easy Game的更多相关文章

  1. zoj 3791 An Easy Game dp

    An Easy Game Time Limit: 2 Seconds      Memory Limit: 65536 KB One day, Edward and Flandre play a ga ...

  2. ZOJ 3791 An Easy Game(DP)

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

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

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

  4. ZOJ 3868 - Earthstone: Easy Version

    3868 - Earthstone: Easy Version Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld ...

  5. 【ZOJ 3844】Easy Task

    题意 每次把序列中最大的数a的一个和最小的数b的一个变成a-b.求最后是否能使序列里的数全部相同,能则输出这个相同的数. 分析 一定是有解的,不断减少最大数的个数,最大数减少为0个时,就是减少了不同数 ...

  6. 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 ...

  7. Easy 2048 Again - ZOJ 3802 像缩进dp

    Easy 2048 Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Dark_sun knows that on a single-tr ...

  8. ZOJ 2969 Easy Task

    E - Easy Task Description Calculating the derivation of a polynomial is an easy task. Given a functi ...

  9. ZOJ 3802 Easy 2048 Again 状态DP

    zoj 上次的月赛题,相当牛的题目啊,根本想不到是状态压缩好吧 有个预先要知道的,即500个16相加那也是不会超过8192,即,合并最多合并到4096,只有2的12次方 所以用状态压缩表示前面有的序列 ...

随机推荐

  1. A Case Study -- Performance Evaluation of a DRAM-Based Solid State Disk

    研究将固态硬盘作为持久存储层和传统硬盘的在数据库性能上的研究

  2. 事件兼容IE

    addEvent:function(target, functionref, tasktype) { if (target.addEventListener) target.addEventListe ...

  3. form表单重置

    Jquery中重置表单的错误姿势 $('#yigeform').reset() 正确姿势 $('#yigeform')[0].reset()

  4. 用VirtualBox构建MySQL测试环境笔记

    网络环境: 宿主机:Win7 VirtualBox 4.1.4 + Ubuntu 11.10 server 64bit 宿主机使用网线的时候,客户机在Bridged Adapter模式下,使用Athe ...

  5. Delphi中的GetEnumName和GetEnumValue的使用方法

    利用TypInfo单元的GetEnumName和GetEnumValue可以遍历任意枚举类型,并获取其名称和值.下面是示例Demo. uses TypInfo; ... procedure TForm ...

  6. Python之路----文件操作

    文件操作 1.能调用方法的一定是对象,比如数值.字符串.列表.元组.字典,甚至文件也是对象,Python中一切皆为对象. str1 = 'hello' str2 = 'world' str3 = ' ...

  7. WPF 数据绑定Bingding基础(第四天)

    程序的本质是数据加算法.数据会在存储.逻辑和展示三个层面沟通,在WPF中,展示层和逻辑层的沟通就使用Data Bingding来实现. Binding即“绑定”,如果把Bingding比作数据的桥梁, ...

  8. 【BZOJ】3309: DZY Loves Math 莫比乌斯反演优化

    3309: DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007) ...

  9. 2016031901 - U盘安装ubuntu系统

    使用U盘安装ubuntu系统 01.进入u盘安装 个人使用的是闪迪U盘安装 02. 个人重装ubuntu 03.进入ubuntu安装界面 04.进入语言界面 05.准备安装ubuntu 06.ubun ...

  10. Command-line tools can be 235x faster than your Hadoop cluster

    原文链接:http://aadrake.com/command-line-tools-can-be-235x-faster-than-your-hadoop-cluster.html Introduc ...