P2679 子串
Posted mzg1805
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了P2679 子串相关的知识,希望对你有一定的参考价值。
#include <bits/stdc++.h> #define read read() #define up(i,l,r) for(register int i = (l);i <= (r);i++) #define down(i,l,r) for(register int i = (l);i >= (r);i--) #define traversal_vedge(i) for(register int i = head[u]; i ;i = e[i].nxt) #define ll long long using namespace std; int read { int x = 0, f = 1; char ch = getchar(); while(ch < 48 || ch > 57) {if(ch == ‘-‘)f = -1; ch = getchar();} while(ch >=48 && ch <=57) {x = 10 * x + ch - 48;ch = getchar();} return x * f; } const int mod = 1000000007; int n,m,maxk,f[2][205][205][2]; char a[1005],b[205]; bool c = 0; int main() { freopen("input.txt","r",stdin); n = read; m = read; maxk = read; scanf("%s",a+1); scanf("%s",b+1); f[0][0][0][0] = f[1][0][0][0] = 1;// 两行0初始化为1; up(i,1,n) { c ^=1; up(j,1,m) up(k,1,maxk) { if(a[i] == b[j]) { f[c][j][k][0] = (f[c^1][j][k][1] + f[c^1][j][k][0])%mod; f[c][j][k][1] = ((f[c^1][j-1][k][1] + f[c^1][j-1][k-1][0])%mod + f[c^1][j-1][k-1][1])%mod; } else { f[c][j][k][0] = (f[c^1][j][k][1] + f[c^1][j][k][0])%mod; f[c][j][k][1] = 0; } } } printf("%d ",(f[n&1][m][maxk][0] + f[n&1][m][maxk][1])%mod); return 0; }
以上是关于P2679 子串的主要内容,如果未能解决你的问题,请参考以下文章