给你两个子串,让你找出来一个最短的字符串包括这两个子串,输出最多的子串有多少种。

类似于最长公共子序列,相等的话长度+1,不想等的话比較长度,使用长度小的。

1577. E-mail

Time limit: 1.0 second

Memory limit: 64 MB
Vasya started to use the Internet not so long ago, so he has only two e-mail accounts at two different servers. For each of them he has a password, which is a non-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 up with a single universal password, which both servers would accept. Vasya can't remember too long passwords, hence he is interested
in a universal password of 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 109 + 7.

Samples

input output
b
ab
1
abcab
cba
4

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define mod 1000000007 const int maxn = 2010; using namespace std; LL dp[maxn][maxn];
LL len[maxn][maxn]; char str1[maxn];
char str2[maxn]; int main()
{
while(~scanf("%s %s",str1+1, str2+1))
{
int n = strlen(str1+1);
int m = strlen(str2+1);
memset(dp, 0, sizeof(dp));
memset(len, 0, sizeof(len));
for(int i = 0; i <= max(n, m); i++)
{
dp[i][0] = 1;
dp[0][i] = 1;
len[i][0] = i;
len[0][i] = i;
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(str1[i] == str2[j])
{
dp[i][j] = dp[i-1][j-1];
len[i][j] = len[i-1][j-1]+1;
continue;
}
if(len[i-1][j] > len[i][j-1])
{
dp[i][j] = dp[i][j-1];
len[i][j] = len[i][j-1]+1;
continue;
}
if(len[i][j-1] > len[i-1][j])
{
dp[i][j] = dp[i-1][j];
len[i][j] = len[i-1][j]+1;
continue;
}
len[i][j] = len[i-1][j]+1;
dp[i][j] += dp[i-1][j]+dp[i][j-1];
dp[i][j] %= mod;
}
}
cout<<dp[n][m]<<endl;
}
return 0;
}

URAL 1577. E-mail(简单二维dp)的更多相关文章

  1. 传纸条 NOIP2008 洛谷1006 二维dp

    二维dp 扯淡 一道比较基本的入门难度的二维dp,类似于那道方格取数,不过走过一次的点下次不能再走(看提交记录里面好像走过一次的加一次a[i][j]的也AC了,,),我记得当年那道方格取数死活听不懂, ...

  2. 关于二维DP————站上巨人的肩膀

    意匠惨淡经营中ing, 语不惊人死不休........ 前几天学了DP,做了个简单的整理,记录了关于DP的一些概念之类的,今天记录一下刚学的一个类型 ----关于二维DP 那建立二维数组主要是干嘛用的 ...

  3. 洛谷p1732 活蹦乱跳的香穗子 二维DP

    今天不BB了,直接帖原题吧  地址>>https://www.luogu.org/problem/show?pid=1732<< 题目描述 香穗子在田野上调蘑菇!她跳啊跳,发现 ...

  4. HDU - 2159 FATE(二维dp之01背包问题)

    题目: ​ 思路: 二维dp,完全背包,状态转移方程dp[i][z] = max(dp[i][z], dp[i-1][z-a[j]]+b[j]),dp[i][z]表示在杀i个怪,消耗z个容忍度的情况下 ...

  5. 洛谷P1048 采药 二维dp化一维

    题目描述 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他带到一个到处都是草药的山洞里对他说:“孩子,这个 ...

  6. 洛谷1387(基础二维dp)

    题目很简单,数据也很小,但是思路不妨借鉴:dp[i][j]代表以(i,j)为右下角的最长正方形边长. 类比一维里面设“以XX为结尾的最XXX(所求)”. 另外define不要乱用!尤其这种min套mi ...

  7. 简单二维元胞自动机 MATLAB实现

    20世纪50年代,乌尔姆和冯·诺依曼(对此人真是崇拜的五体投地)为了研究机器人自我复制的可能性,提出了一种叫做元胞自动机(Cellular Automaton,CA)的算法.该算法采用局相互作用规则, ...

  8. BZOJ 2748: [HAOI2012]音量调节【二维dp,枚举】

    2748: [HAOI2012]音量调节 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2010  Solved: 1260[Submit][Statu ...

  9. To the Max 二维dp(一维的变形)

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...

随机推荐

  1. .netcore下的微服务、容器、运维、自动化发布

    原文:.netcore下的微服务.容器.运维.自动化发布 微服务 1.1     基本概念 1.1.1       什么是微服务? 微服务架构是SOA思想某一种具体实现.是一种将单应用程序作为一套小型 ...

  2. Oracle分页查询的一个存储过程:

    create or replace procedure AspNetOraclePager(       tableName in varchar2, --表名       fields in var ...

  3. IDEA 创建Web项目并在Tomcat中部署运行(转)

    原文地址:https://www.cnblogs.com/tufujie/p/5738250.html IDEA 14.0.5 apache-tomcat-8.0.32 步骤:File->New ...

  4. [TypeScript] Union Types and Type Aliases in TypeScript

    Sometimes we want our function arguments to be able to accept more than 1 type; e.g. a string or an ...

  5. sqoop 1.4.4-cdh5.1.2快速入门 分类: C_OHTERS 2015-06-06 11:40 208人阅读 评论(0) 收藏

    一.快速入门 (一)下载安装 1.下载并解压 wget http://archive.cloudera.com/cdh5/cdh/5/sqoop-1.4.4-cdh5.1.2.tar.gz tar - ...

  6. 公钥,私钥和数字签名这样最好理解 分类: B3_LINUX 2015-05-06 16:25 59人阅读 评论(0) 收藏

    一.公钥加密 假设一下,我找了两个数字,一个是1,一个是2.我喜欢2这个数字,就保留起来,不告诉你们(私钥),然后我告诉大家,1是我的公钥. 我有一个文件,不能让别人看,我就用1加密了.别人找到了这个 ...

  7. MCI

    MCI(Media Control Interface)媒体控件接口是Mircrosoft提供的一组多媒体和文件的标准接口.它的好处是可以方便地控制绝大多数多媒体设备 包括音频,视频,影碟,录像等多媒 ...

  8. Codeforces 467C. George and Job

    DP.... C. George and Job time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. TensorFlow on Windows: “Couldn't open CUDA library cudnn64_5.dll”

    TensorFlow on Windows: "Couldn't open CUDA library cudnn64_5.dll" 在 windows 下,使用 import te ...

  10. JSON序列化自己主动过滤NULL值

    使用Newtonsoft.Json.dll 序列化为json时主动将NULL值过滤掉.详细做法: var jSetting = new JsonSerializerSettings {NullValu ...