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条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结 ...
随机推荐
- 黑马程序员_JavaIO流(二)
字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应类: BufferedWriter BufferedReader 缓冲区要结合流才可以使用. 在流的基础上对流的功能进行了增强. Buffer ...
- [转]The culture name list in C#
Culture Names [C#] This example shows how to get all culture names in the .NET Framework. Use static ...
- ACM2055_ctype.h_cctype
#include<iostream> int main() { using namespace std; int y,count; char x; cin>>count; wh ...
- ORACLE表空间
在ORACLE数据库中,所有数据从逻辑结构上看都是存放在表空间当中,当然表空间下还有段.区.块等逻辑结构.从物理结构上看是放在数据文件中.一个表空间可由多个数据文件组成. 如下图所示,一个数据库由对应 ...
- spring注解理解
步骤一:编写web.xml文件,主要代码如下:<servlet> Java代码 <servlet-name>spmvc</servlet-name> <ser ...
- iOS - 排序的队列中插入数值
http://stackoverflow.com/questions/8180115/nsmutablearray-add-object-with-order 用Selector http://sta ...
- JSP入门:介绍什么是JSP和Servlet(转)
转自:http://developer.51cto.com/art/200907/134506.htm JSP入门:什么是jsp? JSP(Java Server Pages)是由Sun Micros ...
- struts2.1.*中再实现了一个servlet的方法
学习Struts2也有一段时间了,今天用Servlet写了一个验证码,然后搬到Struts2中,惊奇地发现Servlet无法访问,出现404错误!后来折腾了半天,终于找出原因了.这也算我学习中的一个重 ...
- POJ 2175 Evacuation Plan (费用流,负环,消圈法,SPFA)
http://poj.org/problem?id=2175 Evacuation Plan Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- HDU 2435 There is a war (网络流-最小割)
There is a war Problem Description There is a sea. There are N islands in the sea. ...