dp的开关路灯
来源:互联网 发布:通达信选股软件下载 编辑:程序博客网 时间:2024/06/10 01:41
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 ≤ m ≤ n). 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 1100001
Sample Output
2
Hint
100->101->001100->000->001
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const long long int MOD = 1000000009LL;long long C[110][110],dp[110][110];int n,m,K;char s1[110],s2[110];int main(){ for(int i=0;i<110;i++) C[i][i]=1LL,C[i][0]=1LL; for(int i=2;i<110;i++) for(int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD; while(scanf("%d%d%d",&n,&m,&K)!=EOF) { memset(dp,0,sizeof(dp)); scanf("%s%s",s1,s2); int nt=0; for(int i=0;i<n;i++) if(s1[i]!=s2[i]) nt++; dp[0][nt]=1; for(int i=1;i<=m;i++) { for(int j=0;j<=n;j++) { for(int k=max(0,j-K);k<=min(n,j+K);k++) { /// dp[i][j]+=dp[i-1][k]*C[][]*C[][]; int deta=j-k;///不同的位置个数变化量 if(deta>=0) { if(deta==K||(K-deta)%2==0) { dp[i][j]=(dp[i][j]+((dp[i-1][k]*C[k][(K-deta)/2])%MOD*C[n-k][deta+(K-deta)/2])%MOD)%MOD; } } else if(deta<0) { deta*=-1; if(deta==K||(K-deta)%2==0) { dp[i][j]=(dp[i][j]+((dp[i-1][k]*C[k][deta+(K-deta)/2])%MOD*C[n-k][(K-deta)/2])%MOD)%MOD; } } } } } printf("%lld\n",dp[m][0]); } return 0;}
- dp的开关路灯
- 关路灯(区间DP)
- 【DP】洛谷 P1220 关路灯
- 关路灯(区间dp)
- 橘黄的路灯
- 马路上的路灯
- 马路上的路灯
- 路灯
- 路灯
- 路灯
- 路灯
- 路灯
- 路灯
- 路灯
- 路灯
- 路灯
- 区间DP code[vs]1258 关路灯
- 洛谷 P1220 关路灯 (区间DP)
- kconfig与Makefile运行机制
- 2014-8-8 引擎剩余工作排序列表
- HDU 1243 畅通工程 并査集
- mssql到mysql项目的转型完美解决方案剖析
- next数组,你为何如此吊
- dp的开关路灯
- tomcat-redis-session-manager 介绍
- HDU 4911 Inversion
- 从我国户外广告行业现状看其未来走向选择
- C++ new分配内存时的std::bad_alloc异常处理
- 地铁公益广告将狗比作“保安”惹非议被撤销
- 关于对抗缓冲区溢出攻击
- Linux入门第一篇--pS:从今天开始写技术日志
- getAction()