求一个串S有多少子串subS满足s是subS的子序列.len(S)<=100000, len(s)<=100

直接扫一遍...

--------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;
 
typedef long long ll;
 
const int maxn = 109;
 
char S[100009], s[maxn];
int Sn, sn, cnt[maxn], p;
ll ans;
 
int main() {
scanf("%s%s", S, s);
Sn = strlen(S);
sn = strlen(s);
p = 0; ans = 0;
memset(cnt, 0, sizeof cnt);
for(int i = 0; i < Sn; i++) {
for(int j = sn; j-- > 1; )
if(S[i] == s[j]) cnt[j] = max(cnt[j], cnt[j - 1]);
if(s[0] == S[i]) cnt[0] = i + 1;
if(s[sn - 1] == S[i])
ans += (ll) (cnt[sn - 1] - p) * (Sn - i), p = cnt[sn - 1];
}
printf("%lld\n", ans);
return 0;
}

--------------------------------------------------------------------

506. Subsequences Of Substrings

Time limit per test: 0.5 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard

Andrew has just made a breakthrough in steganography: he realized that one can hide a message in a bigger text by making the message a subsequence of the text. We remind that a strings is called a subsequence of string t if one can remove some (possibly none) letters from t and obtain s. Andrew has prepared a text (represented by a string) with a hidden message (represented by another string which is a subsequence of the first string). But it turns out that he doesn't have enough space to write the text, so he wonders if he can remove some letters from the beginning and/or the end of his text in such a way that the hidden message still stays a subsequence of it. You should find out how many ways are there to remove some (possibly none) letters from the beginning of the given text and some (possibly none) letters from the end of the given text in such a way that the given message is a subsequence of the remaining string. Two ways are distinct if the number of letters removed from the beginning or from the end or both are distinct, even if the resulting string is the same. 

Input

The first line of the input file contains the text — a non-empty string of lowercase English letters, no more than  letters long. The second line of the input file contains the message — a non-empty string of lowercase English letters, no more than 100 letters long. It is guaranteed that the message is a subsequence of the given text. 

Output

Output one integer — the sought number of ways. 

Example(s)
sample input
sample output
abraaadabraa baa 
23 

SGU 506.Subsequences Of Substrings的更多相关文章

  1. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

    题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...

  2. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  3. SDU暑期集训排位(4)

    SDU暑期集训排位(4) C. Pick Your Team 题意 有 \(n\) 个人,每个人有能力值,A 和 B 轮流选人,A 先选,B 选人按照一种给出的优先级, A 可以随便选.A 想最大化己 ...

  4. [LeetCode] Count Different Palindromic Subsequences 计数不同的回文子序列的个数

    Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...

  5. Kattis之旅——Divisible Subsequences

    Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...

  6. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  7. [LeetCode] 730. Count Different Palindromic Subsequences 计数不同的回文子序列的个数

    Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...

  8. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. PIC12F508/505/509/510/506/519/526/527单片机破解芯片解密方法!

    IC芯片解密PIC12F508/505/509/510/506/519/526/527单片机破解 单片机芯片解密型号: PIC12F508解密 | PIC12F505解密 | PIC12F506解密  ...

随机推荐

  1. jQuery实现拖动布局并将排序结果保存到数据库

    很多网站的拖动布局的例子都是采用浏览器的COOKIE来记录用户拖动模块的位置,也就是说拖动后各模块的排序位置信息是记录在客户端的cookie里的.当用户清空客户端的cookie或浏览器的cookie过 ...

  2. bootstrap-js(5)工具提示tooltip

    实例 当您想要描述一个链接的时候,工具提示(Tooltip)就显得非常有用.工具提示(Tooltip)插件是受 Jason Frame 写的 jQuery.tipsy 的启发.工具提示(Tooltip ...

  3. Myeclipse 常用操作(待补充)

    1.更改背景色 进入myeclipse工作区,选择window->Preferences->General->Editors->Text Editors->Backgro ...

  4. leetcode Merge K sorted Lists python

    # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...

  5. js闭包陷阱问题

    JavaScript是一种非常强大的函数式编程语言,可以动态创建函数对象. 由于JavaScript还支持闭包(Closure),因此,函数可以引用其作用域外的变量,非常强大. 来看看在JavaScr ...

  6. 关于jQuery中toggle()函数的使用

    今天遇到一个有趣的例子,将它记录下来. 一个一级菜单,里边有一个二级菜单,二级菜单是通过锚点来链接页面元素的.想要实现的效果是当点击锚点时,页面链接到相应锚点,同时二级菜单隐藏,再点击一级菜单时,继续 ...

  7. javascript 常用函数

    //获取元素的样式值. function getStyle(elem,name){ if(elem.style[name]){ return elem.style[name]; }else if(el ...

  8. JDBC连接数据库概述

    直接介绍JDBC连接数据库的流程及其原理 创建一个以JDBC连接数据库的程序,包含7个步骤 1.加载JDBC数据库驱动 在连接数据库之前,首先要加载想要连接的数据库的驱动,就是数据库厂商提供的jar包 ...

  9. mud目录命令说明

      目錄結構 以下列出的是 ES2 mudlib 根目錄下標準的子目錄結構,以及簡短的說明. /adm 儲存由系統管理者所管理的程式與資料檔. /std 儲存標準物件的程式碼. /obj 儲存通用物件 ...

  10. Generator & Co

    Generator 搬运自 http://es6.ruanyifeng.com/#docs/generator 如果没有babel等环境也可以在线体验 可以在http://www.es6fiddle. ...