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

类似于最长公共子序列,相等的话长度+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;
}

最新文章

  1. Asp.net中存储过程拖拽至dbml文件中,提示无法获得返回值
  2. M站开发规范——By Klax
  3. jsp_内置对象_request
  4. jQueryMobile控件之按钮
  5. JSBinding + SharpKit / 需要注意及不支持的列表
  6. 在Entity Framework中重用现有的数据库连接字符串
  7. HDOJ/HDU 1161 Eddy&#39;s mistakes(大写字母转换成小写字母)
  8. c++primerplus(第六版)编程题&mdash;&mdash;第6章(分支语句和逻辑运算符)
  9. 根据打开页面加载不同Js
  10. 转: mysql create view 创建视图
  11. iOS开发之圆角指定
  12. 14. leetcode 383. Ransom Note
  13. ML神器:sklearn的快速使用
  14. jhipster生成项目无法使用restful请求,报access_denied 403错误
  15. [蓝桥杯]PREV-15.历届试题_格子刷油漆
  16. 用“人话”解释不精确线搜索中的Armijo-Goldstein准则及Wolfe-Powell准则
  17. JavaScript数组学习总结
  18. 【阿里云】云服务器 ECS部署网站
  19. Nginx ab压力测试
  20. linux kernel swap daemon

热门文章

  1. angular6添加material-svgIcon
  2. 9.11 Binder系统_分层
  3. 【习题 5-6 UVA-1595】Symmetry
  4. ArcGIS中ObjectID,FID和OID字段区别
  5. ios移动旋转缩放动画
  6. [Angular2 Router] Auxiliary Routes bit by bit
  7. java实现微信支付宝等多个支付平台合一的二维码支付(maven+spring springmvc mybatis框架)
  8. web中的重定向与转发
  9. [HTTP] Understand 2xx HTTP Status Code Responses
  10. [Angular] How to styling ng-content