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条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结 ...
随机推荐
- Templates 模板:
Templates 模板: ########################温金 $template wj-flow01,"/data01/applog_backup/winfae_log/ ...
- Linux系统编程(36)—— socket编程之UDP详解
UDP 是User DatagramProtocol的简称,中文名是用户数据报协议.UDP协议不面向连接,也不保证传输的可靠性,例如: 1.发送端的UDP协议层只管把应用层传来的数据封装成段交给IP协 ...
- windows下MongoDB的安装及配置
http://jingyan.baidu.com/article/d5c4b52bef7268da560dc5f8.html 使用MongoVUE链接本地mongodb 基本用法见这里:http:// ...
- Generating SSH Keys [Ubuntu Linux]
Generating SSH Keys We strongly recommend using an SSH connection when interacting with GitHub. SSH ...
- storm 事务和DRPC结合
示例代码: package com.lky.topology; import backtype.storm.Config; import backtype.storm.LocalCluster; im ...
- 面试al tx
阿里: 一面: 1:写代码,给三个数组abc,每个数组若干数字,判断一个数字在不在三个数组中.用的map解决. 2:例举知道的排序,写出归并排序代码. 3:剩下的都是小题目了:包括三次握手,tc ...
- UML[1] UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)(转)
转自:http://blog.csdn.net/zhaoxu0312/article/details/7212152 继承.实现.依赖.关联.聚合.组合的联系与区别 分别介绍这几种关系: 继承 指的是 ...
- MYSQL常用操作函数的封装
1.mysql常用函数封装文件:mysql.func.php <?php /** * 连接MYSQL函数 * @param string $host * @param string $usern ...
- 使用FastClick的同时造成元素上的trigger('click')无法触发的解决办法
现象还原: 1. 初始化进入多规格卖场商详页的时候,chrome模拟器切换到安卓环境下,点击加入购物车,规格弹出页没有展示.而在PC和IOS模拟器下,可以弹出规格页 2. 点击加入购物车时,使用 $( ...
- Android Game
收起相关游戏 cytus 机械迷城 小小炼狱 deemo 神庙逃离 现代战争4零点行动 植物大战僵尸2中文版 时空幻境 无尽之剑3 超级救火队 迷你冲撞 大战僵尸鸟 侍魂2 flappy bird 混 ...