Codeforces 163A Substring and Subsequence
http://codeforces.com/problemset/problem/163/A?mobile=true
题目大意:给出两个串,问a的连续子串和b的子串(可以不连续)相同的个数。
思路:在LCS上加点改动
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
const int Mod=;
char a[],b[];
int n,m,f[][];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
scanf("%s",a+);n=strlen(a+);
scanf("%s",b+);m=strlen(b+);
for (int i=;i<=n;i++)
if (a[i]==b[]) f[i][]=;
for (int i=;i<=m;i++)
if (a[]==b[i]) f[][i]=;
int ans=;
for (int i=;i<=n;i++){
for (int j=;j<=m;j++){
f[i][j]=f[i][j-];
if (a[i]==b[j])
(f[i][j]+=f[i-][j-]+)%=Mod;
}
ans=(ans+f[i][m])%Mod;
}
printf("%d\n",ans);
}
Codeforces 163A Substring and Subsequence的更多相关文章
- CodeForces 163A Substring and Subsequence dp
A. Substring and Subsequence 题目连接: http://codeforces.com/contest/163/problem/A Description One day P ...
- Codeforces 163A Substring and Subsequence:dp【子串与子序列匹配】
题目链接:http://codeforces.com/problemset/problem/163/A 题意: 给你两个字符串a,b,问你有多少对"(a的子串,b的子序列)"可以匹 ...
- Codeforce 163 A. Substring and Subsequence DP
A. Substring and Subsequence One day Polycarpus got hold of two non-empty strings s and t, consist ...
- CF-163A Substring and Subsequence 字符串DP
Substring and Subsequence 题意 给出两个字符串s,t,求出有多少对s的子串和t的子序列相等. 思路 类似于最长公共子序列的dp数组. dp[i][j]表示s中以i为结尾的子串 ...
- Codeforces 919D - Substring
919D - Substring 思路: 拓扑排序判环+DAG上dp+记忆化搜索 状态:dp[i][j]表示以i为起点的路径中j的最大出现次数 初始状态:dp[i][j]=1(i have no so ...
- 【29.41%】【codeforces 724D】Dense Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 919D Substring (拓扑排序+树形dp)
题目:Substring 题意:给你一个有向图, 一共有n个节点 , m条变, 一条路上的价值为这个路上出现过的某个字符最多出现次数, 现求这个最大价值, 如果价值可以无限大就输出-1. 题解:当这个 ...
- Codeforces 919D Substring 【拓扑排序】+【DP】
<题目链接> 题目大意:有一个具有n个节点,m条边的有向图,每个点对应一个小写字母,现在给出每个顶点对应的字母以及有向边的连接情况,求经过的某一条路上相同字母出现的最多次数.如果次数无限大 ...
- CodeForces - 919D Substring (拓扑排序+dp)
题意:将一个字符串上的n个字符视作点,给出m条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结 ...
随机推荐
- Linux sar使用
[root@ywcrmdb ~]# sar -d 1 10 Linux 2.6.32-220.el6.x86_64 (ywcrmdb) 2014年04月19日 _x86_64_ (4 CPU) 1 ...
- 算法导论(第三版)Problems2(归并插入排序、数列逆序计算)
讨论内容不说明,仅提供相应的程序. 2.1:归并插入排序θ(nlgn) void mergeInsertionSort(int a[], int l, int r, int k) { int m; & ...
- linux中cat、more、less、tail、head命令
cat命令功能用于显示整个文件的内容单独使用没有翻页功能因此经常和more命令搭配使用,cat命令还有就是将数个文件合并成一个文件的功能. more命令功能:让画面在显示满一页时暂停,此时可按空格健继 ...
- memcached学习——分布式算法(Consistant hash + 虚拟节点)(三)
1.取余算法 优点:数据分布均匀缺点:当服务器动态的添加.删除节点或者某台server down掉,会导致命中率超大幅度下降,甚至导致服务不可用 2.Consistant Hash算法:一致性哈希算法 ...
- prototype对象的真正作用
参考阮一峰的文章:http://javascript.ruanyifeng.com/oop/encapsulation.html prototype对象的真正作用 在JavaScript语言中,每一个 ...
- 读《MacTalk·人生元编程》及Mac经常使用软件
引子 池建强的Blog:http://www.cnblogs.com/chijianqiang/ 用了1年多的黑苹果,是用Windows的思维用UI.用Linux的思维用Shell,折腾的是联想E49 ...
- 浅谈C++中的那些内存泄露
尽管学过C语言.可是C++里面的一些基础还是不太懂,还须要再掌握. 老范也開始要讲C++设计模式了,必须快点看了.不然就要白花窝滴钱了. 对于内存泄露,我的个人理解就是程序在执行过程中,自己开辟了空间 ...
- Android文字的复制和粘贴
Android中提供了简单的额复制粘贴功能.代码很简单 复制文字的代码: ClipboardManager cbm= (ClipboardManager) MainActivity.this .get ...
- Win32<CreatFile>
CreateFile函数详解 CreateFile The CreateFile function creates or opens the following objects and returns ...
- 打开新窗口(window.open)
open() 方法可以查找一个已经存在或者新建的浏览器窗口. 语法: window.open([URL], [窗口名称], [参数字符串]) 参数说明: URL:可选参数,在窗口中要显示网页的网址或路 ...