[NOIP2015] substring explanations

Title Description

Contains only two strings lowercase letters A and B.

A string is now removed from the k-th non-overlapping non-empty string, then this string as a k-th order they appear in the A string obtained sequentially connecting a new string, ask how many programs can be this makes the new string and the string is equal to B?

Note: substring withdrawn position different from different schemes are also considered.

Input Format

The first three lines are positive integers n, m, k, k respectively represent the length, B the length of the string, and the string description of the problem mentioned in A, between each two integers separated by a space.

The second line contains a string of length n, a string representing A. 

The third line contains a string of length m the string representing B.

Output Format

The output common line, contains an integer representing the number of programs required.

Since the answer may be large, so the answer to the result output required here modulo 1,000,000,007.

data range


$ 1 \ n \ the 1000 \\\\ 1 \ m \ the 200 \\\\ 1 \ k \ m $ \\\\

 

 

$Solution:$

As long as you see it is dp done well.

Provided $ dp [i] [j] [k] [0/1] $ represents a match to the bit i, b j bits has been completed before the matching substrings with a k, a current location of the election is not selected the number of programs.

Consider first the case of not selected, apparently $ dp [i] [j] [k] [0] = dp [i-1] [j] [k] [0] + dp [i-1] [j ] [k] [1] $. The last option is not selected can be.

If you choose this one, we must ensure that $ a_i = b_j $, then you either that string in the case of the one before the election also follow, but also open a new string, and open a new string and on a bit choose not vote for nothing, so the three added.

Scroll array.

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1005;
int n,m,K;
char a[N],b[N];
ll dp[2][202][202][2];
int main ()
{
    scanf("%d%d%d",&n,&m,&K);
    scanf("%s",a+1);scanf("%s",b+1);
    dp[0][0][0][0]=dp[1][0][0][0]=1;
    int now=0,pre=1;
    for(int i=1;i<=n;i++)
    {
        now^=1,pre^=1;
        //memset(dp[now],0,sizeof(dp[now]));
        for(int j=1;j<=m;j++)
        {
            for(int k=1;k<=K;k++)
            {
                if(a[i]==b[j])
                    dp[now][j][k][1]=(dp[pre][j-1][k-1][0]+dp[pre][j-1][k][1]+dp[pre][j-1][k-1][1])%mod;
                else dp[now][j][k][1]=0;
                dp[now][j][k][0]=(dp[pre][j][k][0]+dp[pre][j][k][1])%mod;
            }
        }
    }
    ll ans=(dp[now][m][K][0]+dp[now][m][K][1])%mod;
    cout<<ans<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Rorschach-XR/p/11670766.html