ural 1577 E-mail

本文介绍了一种算法,用于找到两个不同邮件服务器接受的最短通用密码的数量。通过动态规划方法,结合最长公共子序列思想,实现了高效求解。

ural 1577 E-mail



E-mail
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u

[]  [Go Back]  [Status]  

Description

Vasya started to use the Internet not so long ago, so he hasonly two e-mail accounts at two different servers. For each of them he has a password, which is anon-empty string consisting of only lowercase latin letters. Both mail servers accept a string as a password if and only if the real password is its subsequence.
Vasya has a hard time memorizing both passwords, so he would like to come upwith a single universal password, which both servers would accept. Vasya can'tremember too long passwords, hence he is interested in a universal passwordof a minimal length. You are to help Vasya to find the number of such passwords.

Input

The input consists of 2 lines, each of them containing the real password for one of the servers. The length of each password doesn't exceed 2000 characters.

Output

Output the number of universal passwords of minimal length modulo 10 9 + 7.

Sample Input

inputoutput
b
ab
1
abcab
cba
4

Hint

In the second sample, the passwords of minimal length are the following: abcaba, abcbab, acbcab, cabcab.


开始拿到这个题目没有思路,忽然发现这个题目很想最长公共子序列,而且长度 为 2000,如果想 dp 求最长公共子序列那样肯定O(n^2) 肯定可以解决

于是我试着在纸上模拟求解LIS,顺着求LIS的路径竟然推出了样例



#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=2010;
const int mod=1000000007;
int dp[maxn][maxn],num[maxn][maxn];
char s1[maxn],s2[maxn];

int main()
{
    while(scanf("%s %s",s1+1,s2+1)==2)
    {
        //cout<<"bug"<<endl;
        int len1=strlen(s1+1),len2=strlen(s2+1);
        for(int i=1;i<=len2;i++) num[0][i]=1,dp[0][i]=i;
        for(int i=1;i<=len1;i++) num[i][0]=1,dp[i][0]=i;
        dp[0][0]=0;
        num[0][0]=1;

        //cout<<len1<<" "<<len2<<endl;

        for(int i=1;i<=len1;i++)
        for(int j=1;j<=len2;j++)
          if(s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
          else dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]+1);

        for(int i=1;i<=len1;i++)
        for(int j=1;j<=len2;j++)
        {
            num[i][j]=0;
            if(s1[i]==s2[j]) num[i][j]=(num[i][j]+num[i-1][j-1])%mod;
            else{
              if(dp[i][j]==dp[i-1][j]+1) num[i][j]=(num[i][j]+num[i-1][j])%mod;
              if(dp[i][j]==dp[i][j-1]+1) num[i][j]=(num[i][j]+num[i][j-1])%mod;
            }
        }
        printf("%d\n",num[len1][len2]);
    }
    return 0;
}


【SCI级别】多策略改进鲸鱼优化算法(HHWOA)和鲸鱼优化算法(WOA)在CEC2017测试集函数F1-F30寻优对比内容概要:本文档主要介绍了一项关于多策略改进鲸鱼优化算法(HHWOA)与标准鲸鱼优化算法(WOA)在CEC2017测试集函数F1-F30上进行寻优性能对比的研究,属于智能优化算法领域的高水平科研工作。文中通过Matlab代码实现算法仿真,重点展示了HHWOA在收敛速度、寻优精度和稳定性方面的优势,体现了多策略改进的有效性。该研究适用于复杂优化问题求解,尤其在工程优化、参数辨识、机器学习超参数调优等领域具有应用潜力。; 适合人群:具备一定算法基础和Matlab编程能力的研究生、科研人员及从事智能优化算法开发与应用的工程技术人员,尤其适合致力于SCI论文写作与算法创新的研究者。; 使用场景及目标:①用于理解鲸鱼优化算法的基本原理及多策略改进思路(如种群初始化、非线性收敛因子、精英反向学习等);②为智能优化算法的性能测试与对比实验提供CEC2017标准测试平台的实现参考;③支撑学术研究中的算法创新与论文复现工作。; 阅读建议:建议结合提供的Matlab代码进行实践操作,重点关注HHWOA的改进策略模块与WOA的差异,通过重复实验验证算法性能,并可将其思想迁移至其他优化算法的改进中,提升科研创新能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值