Two
来源:互联网 发布:蜂云网络51订货网 编辑:程序博客网 时间:2024/05/17 05:17
Two
.
.
题意:给出a,b两个字符串,问他们不必连续的字串中有多少对相同。
.
.
解法:dp。f[i]表示对于b串当前读到的数字匹配到a串的第i个位置一共有的次数。
.
.
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>using namespace std;const int maxn = 2000;const int mo = 1000000007;int a[maxn], f[maxn], n, m, sum, x, add, ans;int main() { while ((scanf("%d %d", &n, &m)) != EOF) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(f, 0, sizeof(f)); for (int j = 1; j <= m; j++) { scanf("%d", &x); sum = 0; for (int i = 1; i <= n; i++) { add = 0; if (a[i] == x) add = sum+1; sum = (sum+f[i])%mo; f[i] = (f[i]+add)%mo; } } ans = 0; for (int i = 1; i <= n; i++) ans = (ans+f[i])%mo; printf("%d\n", ans); }}
0 0
- two:
- two
- two
- Two
- two
- two
- Two
- TWO
- two
- two and two and two two...
- HackRank Two Two
- Two Brothers
- css two
- Function Two
- two years
- Two Ends
- Two Strings
- Two Sum
- Maven中Spring-Data-Redis存储对象(redisTemplate)
- 处理区间计数问题
- <ROS> 机器人描述--URDF和XACRO
- 非关系型数据库
- KMP(字符串匹配算法)基本介绍
- Two
- 欢迎使用CSDN-markdown编辑器
- 使用Handler时new失败
- python 外部传参sys.argv 的使用
- nginx负载配置
- Sublime Text3 配置Lua运行环境
- 安卓学习笔记之Drawable
- Angular 2的HTML5 pushState在ASP.NET Core上的解决思路
- JMS入门(七)---JMSReplyTo