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的更多相关文章

  1. CodeForces 163A Substring and Subsequence dp

    A. Substring and Subsequence 题目连接: http://codeforces.com/contest/163/problem/A Description One day P ...

  2. Codeforces 163A Substring and Subsequence:dp【子串与子序列匹配】

    题目链接:http://codeforces.com/problemset/problem/163/A 题意: 给你两个字符串a,b,问你有多少对"(a的子串,b的子序列)"可以匹 ...

  3. 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 ...

  4. CF-163A Substring and Subsequence 字符串DP

    Substring and Subsequence 题意 给出两个字符串s,t,求出有多少对s的子串和t的子序列相等. 思路 类似于最长公共子序列的dp数组. dp[i][j]表示s中以i为结尾的子串 ...

  5. Codeforces 919D - Substring

    919D - Substring 思路: 拓扑排序判环+DAG上dp+记忆化搜索 状态:dp[i][j]表示以i为起点的路径中j的最大出现次数 初始状态:dp[i][j]=1(i have no so ...

  6. 【29.41%】【codeforces 724D】Dense Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. Codeforces 919D Substring (拓扑排序+树形dp)

    题目:Substring 题意:给你一个有向图, 一共有n个节点 , m条变, 一条路上的价值为这个路上出现过的某个字符最多出现次数, 现求这个最大价值, 如果价值可以无限大就输出-1. 题解:当这个 ...

  8. Codeforces 919D Substring 【拓扑排序】+【DP】

    <题目链接> 题目大意:有一个具有n个节点,m条边的有向图,每个点对应一个小写字母,现在给出每个顶点对应的字母以及有向边的连接情况,求经过的某一条路上相同字母出现的最多次数.如果次数无限大 ...

  9. CodeForces - 919D Substring (拓扑排序+dp)

    题意:将一个字符串上的n个字符视作点,给出m条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结 ...

随机推荐

  1. css属性之@media

    Base Browsers: IE6.0+, Firefox2.0+, Chrome4.0+, Safari6.0+, Opera15.0+ <expression>:指定媒体查询使用的媒 ...

  2. BZOJ3315: [Usaco2013 Nov]Pogo-Cow

    3315: [Usaco2013 Nov]Pogo-Cow Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 143  Solved: 79[Submit] ...

  3. HDU_2045——RPG问题,递推

    Problem Description 人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即"可乐"),经过多方打探,某资深Co ...

  4. [LeetCode] 134. Gas Station 解题思路

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  5. powerdesigner 字段大小写转换\id 自增

    转换:tools --> model options-->naming convention  name code 自增: 在你所要设为自增型的键上(比如你的id)双击 ,弹出一个Colu ...

  6. JAVA 面试整理,面试汇总

    1.JAVA是通过重写和重载来实现多态性的. 重写:同样的方法签名,不同的方法实现 重载:同样的方法名,不同的参数类型或参数个数 2.JAVA中如果存在不再使用的对象,但是程序又持有该对象的引用,就会 ...

  7. 关于javax.crypto.BadPaddingException: Blocktype错误的几种解决方法

    此文章转载自:http://www.myexception.cn/mobile/1259076.html 关于javax.crypto.BadPaddingException: Blocktype异常 ...

  8. (转)keytools命令

    结合网络资源,对keytool使用总结,以备后用: Keytool是一个Java数据证书的管理工具 ,Keytool将密钥(key)和证书(certificates)存在一个称为keystore的文件 ...

  9. Linux下编译安装Apache及模块

    Apache是时下最流行的Webserver软件之中的一个,支持多平台,可高速搭建web服务,并且稳定可靠.并可通过简单的API扩充.就能够集成PHP/Python等语言解释器. 文章这里解说怎样在l ...

  10. 用java实现Simsimi小黄鸡接口

    package com.iask.webchat.chatmachine; import java.io.BufferedReader; import java.io.InputStream; imp ...