意甲冠军:给定两个01弦s1,s2.每一个变化s1在m字 - 位。要求k制作步骤之后s1变s2有多少种方法。

解法:DP,关键是状态的设计。考虑还是唯一性和可传递性。dp[i][j]表示第i步后有j个不同到目标的走法数。记忆化搜索dp[0][dif](dif表示初始时不同字符的个数)。

转移时候枚举选择情况就可以。

代码:

/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std; #define eps 1e-8
const double pi=acos(-1.0);
typedef long long LL;
const int Max=110;
const int INF=1000000009; int n,k,m;
string s1,s2;
LL C[Max][Max];
int init()
{
for(int i=0; i<Max; i++)
for(int j=0; j<=i; j++)
C[i][j]=j? (C[i-1][j-1]+C[i-1][j])%INF:1;
}
LL dp[Max][Max];
int dif;
LL dfs(int step,int num)
{
if(dp[step][num]!=-1)
return dp[step][num];
LL ans=0;
for(int i=0; i<=num; i++)
{
if(i+n-num<m)
continue;
if(i>m)
break;
ans=(ans+(C[num][i]*C[n-num][m-i])%INF*dfs(step+1,num-i+m-i))%INF;
}
return dp[step][num]=ans;
}
int main()
{
init();
while(scanf("%d%d%d",&n,&k,&m)==3)
{
dif=0;
memset(dp,-1,sizeof dp);
cin>>s1>>s2;
for(int i=0; i<n; i++)
if(s1[i]!=s2[i])
dif++;
dp[k][0]=1;
for(int i=1;i<=n;i++)
dp[k][i]=0;
cout<<dfs(0,dif)<<'\n';
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

zoj3791(An Easy Game) DP的更多相关文章

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

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

  2. HDU 4359 Easy Tree DP?

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

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

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

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

  5. ZOJ3791 An Easy Game(DP)

    给两个长n的01串s1和s2,要对s1进行k次修改,每次修改m个不同位置,问有几种方式修改成s2. 想偏了,只想到原始的01数值是不重要的,因为每个位置修改次数的奇偶性是确定的这一层.. 其实,这题只 ...

  6. CF1096:D. Easy Problem(DP)

    Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement ...

  7. 【BZOJ3450】Easy [期望DP]

    Easy Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 某一天WJMZBMR在打osu~~ ...

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

  9. bzoj 3450 Tyvj1952 Easy (概率dp)

    3450: Tyvj1952 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下这个游戏的规则有n次点击要做,成功了就是o,失败 ...

随机推荐

  1. Linux下一个php+mysql+nginx构建编译(三)

    在此之前一直是一个关键构建webserver.但一个关键的建筑环境都比较旧的.假定使用一个相对较新的环境,尤其是正式的server.您必须手动编译自己建(基于以下的结构linux centos6.5 ...

  2. 玩转html5(三)---智能表单(form),使排版更加方便

    <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...

  3. Light OJ Dynamic Programming

    免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...

  4. BootStrap布局案例

    BootStrap布局 bootstrap 2.3版与3.0版的使用区别 http://www.weste.net/2013/8-20/93261.html 以一个博客系统的首页,来介绍如何布局 1, ...

  5. Oracle Instanc Client安装命令工具

    条件 1.Linux RHEL 6.X X86_64操作系统 2.从安装Oracleserver的server此次收购Oracle相关文件(同OS) 软件下载 从Oracle包: 1)  instan ...

  6. Web静态和动态项目委托代理基于面向方面编程AOP

    本来每天更新,我一般喜欢晚上十二点的时候发文章,结果是不是愚人节?校内网也将是非常有趣,破,把我给打. ..好吧-从今天开始的话题AOP.AOP太重要了,所以把第二篇文章谈论这个话题,AOP它是Spr ...

  7. [LeetCode82]Remove Duplicates from Sorted List II

    题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct  ...

  8. 手提wifi双卡配置+window7同时多用户远程+有些公司限制网络环境方案

    该公司只提供几台机器,同时限制并连接到内部办公网络的机, 我们更多的临时工作人员,项目紧张,而另一种是太麻烦了申请, 当被问及其他网络管理,说没有变通方法. 在我的尝试,最后,找到一个解决方案; 解决 ...

  9. Windows 8实例教程系列 - 数据绑定高级实例

    原文:Windows 8实例教程系列 - 数据绑定高级实例 上篇Windows 8实例教程系列 - 数据绑定基础实例中,介绍Windows 8应用开发数据绑定基础,其中包括一些简单的数据绑定控件的使用 ...

  10. 读书时间《JavaScript高级程序设计》三:函数,闭包,作用域

    上一次看了第6章,面向对象.这里接着看第7章. 第7章:函数表达式 定义函数有两种方式:函数声明.函数表达式 //函数声明 function functionName(arg0,arg1,arg2){ ...