zoj3791(An Easy Game) DP
意甲冠军:给定两个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的更多相关文章
- HDU 4359——Easy Tree DP?——————【dp+组合计数】
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 4359 Easy Tree DP?
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )
D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...
- 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 ...
- ZOJ3791 An Easy Game(DP)
给两个长n的01串s1和s2,要对s1进行k次修改,每次修改m个不同位置,问有几种方式修改成s2. 想偏了,只想到原始的01数值是不重要的,因为每个位置修改次数的奇偶性是确定的这一层.. 其实,这题只 ...
- CF1096:D. Easy Problem(DP)
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement ...
- 【BZOJ3450】Easy [期望DP]
Easy Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 某一天WJMZBMR在打osu~~ ...
- 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 ...
- bzoj 3450 Tyvj1952 Easy (概率dp)
3450: Tyvj1952 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下这个游戏的规则有n次点击要做,成功了就是o,失败 ...
随机推荐
- UML简单梳理类图
依赖 Dependency Class Car{} Class Person{ int a; static int b public void buy(Car c){ int c; .... } } ...
- effective c++ 条款12 copy all parts of an object
这经常发生在更改代码的时候,当有自己的copy 赋值函数或者copy 构造函数时,编译器就不会维护这两个函数.导致发生遗忘. 可能出现的场景 class Customer { private: std ...
- 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern)
原文:乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) 作者:webabc ...
- 【Spring】Spring学习笔记-01-入门级实例
听说当前Spring框架很流行,我也准备好好学学Spring开发,并将学习的过程和大家分享,希望能对志同道合的同学有所帮助. 以下是我学习Spring的第一个样例. 1.Spring开发环境的搭建 我 ...
- Windows8.1和Ubuntu14.04双系统卸载Ubuntu參考教程[图]
我之前编写并公布了<Windows8.1安装Ubuntu14.04双系统參考教程及双硬盘注意事项>这篇教程,而本文提供的卸载Ubuntu方法适用于这篇教程,其它方法安装的Ubuntu可适当 ...
- hbase开放lzo压缩
hbase仅仅支持对gzip的压缩,对lzo压缩支持不好. 在io成为系统瓶颈的情况下,一般开启lzo压缩会提高系统的吞吐量. 但这须要參考详细的应用场景,即是否值得进行压缩.压缩率是否足够等等. ...
- 关于WCF的引用,添加服务和添加web服务的区别
原文:关于WCF的引用,添加服务和添加web服务的区别 本章内容主要是根据我做的实验来阐述这2种添加服务针对WCF的不同之处,我们按照示例一步一步来看. 如下是工程的结构: 该WCF服务是通过控制台程 ...
- PKU A Simple Problem with Integers (段树更新间隔总和)
意甲冠军:一个典型的段树C,Q问题,有n的数量a[i] (1~n),C, a, b,c在[a,b]加c Q a b 求[a,b]的和. #include<cstdio> #include& ...
- MD5和Base64
一. 简述 MD5: 全称为message digest algorithm 5(信息摘要算法), 能够进行加密, 可是不能解密, 属于单向加密, 通经常使用于文件校验 Base64: 把随意序列的8 ...
- Oracle Net Listener Parameters (listener.ora)(转)
12/20 7 Oracle Net Listener Parameters (listener.ora) This chapter provides a complete listing of th ...