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,失败 ...
随机推荐
- 【牛刀小试2】password保
]password保 主要知识: 1. while循环 2. do-while循环 3. if-else 4. strcmp()函数 [充电一下 ...
- HDU 1051:Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Android的第二次增加SurfaceView基本使用
本文来源于http://blog.csdn.net/hellogv/ ,引用必须注明出处. 上次介绍MediaPlayer的时候略微介绍了SurfaceView,SurfaceView因为能够直接从内 ...
- 《反project核心原则》说明
致亲爱的中国读者: 大家好 !我是<逆向project核心原理> 作者 李承远(ReverseCore). (韩文博客地址:www.reversecore.com) 首先.非常高兴我的 ...
- ps设计资料整理
零基础学会建立一个简单化妆品网站—前台设计篇1[PS画草图] http://xiebiji.com/2008/09/huazhuang4/?wptheme=Plainscape&ie=1 PS ...
- js“分享到”侧边框伸缩实现
思路: 1,临界值是 -150 和 0 如果大于临界值,就要隐藏 2,隐藏:速度为负 显示:速度为正 3,如果与临界值相等,就清空定时器 否则,就运动 ------------------------ ...
- 怎么样cocos2d-x正在使用ECS(实体-包裹-制)建筑方法来开发一款游戏?
简介 在我的博客,我翻译的几篇文章ECS文章.这些文章都是从Game Development站点.假设你对这个架构方式还不是非常了解的话.欢迎阅读理解 组件-实体-系统和实现 组件-实体-系统. 我发 ...
- CareerCup chapter 1 Arrays and Strings
1.Implement an algorithm to determine if a string has all unique characters What if you can not use ...
- 认识Underscore
Underscore一个JavaScript实用库,提供了一整套函数式编程的实用功能,但是没有扩展任何JavaScript内置对象.它弥补了部分jQuery没有实现的功能,同时又是Backbone.j ...
- HDU 1698 Just a Hook (段树更新间隔)
Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing for m ...