zoukankan      html  css  js  c++  java
  • SGU 506.Subsequences Of Substrings

    求一个串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 ", 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 
  • 相关阅读:
    print(end=" ") 滚动输出到屏幕
    写入到csv文件的两种方式(pd.DaaFrame 和 csv.writerow)
    pytorch 损失函数(nn.BCELoss 和 nn.CrossEntropyLoss)(思考多标签分类问题)
    pytorch实战(二)hw2——预测收入是否高于50000,分类问题
    信用卡新颖的攻击方式,黑客可非接触式卡进行交易
    微软结束对SolarWinds黑客的内部调查
    Apple M1芯片首款恶意软件曝光
    新的Office恶意软件,黑客可远程窃取信息
    如何审核Active Directory中的密码更改
    特斯拉恶意软件使用新的传送和规避技术
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/5049346.html
Copyright © 2011-2022 走看看