Hidden Message

本文探讨了如何根据给定的三个子句和原始句子,计算出满足John发现模式的分词方式数量,即找到让子句组合与原句字母相同且顺序不变的分组方法。问题涉及字符串处理和动态规划求解模运算。

Hidden Message

时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述 

John was reading the local newspaper, and noticed that the phrase “chime a cork teen” could be
split into three sub-phrases “eat”, “more”, and “chicken”. Note that the three sub-phrases
combined contain exactly the same letters as the original phrase and the letters in each sub-phrase
appear in the same order as they appear in the original phrase. Note also that the number of
occurrences of each letter in the three sub-phrases combined is the same as that of the original
phrase.
John began to theorize that the newspapers were sending him messages, but you decide to show
him that a message like that was not abnormal. You want to determine the number of ways a

phrase can be broken down into three words that John finds.

Given three sub-phrases and the original phrase, determine the number of ways the sub-phrases
can be formed from the original phrase. The number of ways can be quite large, so determine the
number modulo 1,000,000,007. 
 

输入描述:

The input consists of four lines. Each of the first three input lines contains 1-100 lowercase letters,
representing a sub-phrase. The fourth input line contains 3-300 lowercase letters, representing the
original phrase. Note that the sum of the lengths of the three sub-phrases is equal to the length of
the original phrase.

输出描述:

Print a single integer representing the number of ways to partition the original phrase into three
groups where each group is one of the three sub-phrases. Print the count modulo 1,000,000,007.

示例1

输入

复制

eat
more
chicken
chimeacorkteen

输出

复制

2

示例2

输入

复制

the
great
depression
depressigortheneat

输出

复制

2

示例3

输入

复制

a
a
a
aaa

输出

复制

6
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll dp[200][200][200];
const int maxn=100010;
int main(){
    char a[110];
    char b[110];
    char c[110];
    char d[500];
    int la,lb,lc,ld;
    cin>>a+1>>b+1>>c+1>>d+1;
    la=strlen(a+1);
    lb=strlen(b+1);
    lc=strlen(c+1);
    ld=strlen(d+1);
    dp[0][0][0]=1;
    for(int i=1;i<=ld;i++){
        for(int j=0;j<=la;j++){
            for(int k=0;k<=lb;k++){
                for(int l=0;l<=lc;l++){
                    if(j+k+l!=i) continue;
                    if(d[i] == a[j] && j - 1 >= 0) dp[j][k][l] += dp[j-1][k][l] % mod;
                    if(d[i] == b[k]&& k - 1 >= 0) dp[j][k][l] += dp[j][k-1][l] % mod;
                    if(d[i] == c[l]&& l - 1 >= 0) dp[j][k][l] += dp[j][k][l-1] % mod;
                }
            }
        }
    }
    cout<<dp[la][lb][lc]%mod;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值