bzoj4503: Two strings of Bitset

Source: Internet
Author: User
Tags bitset

Tag: While scanf%s turn double | | Char its online

Topic links

bzoj4503: Two strings

Exercises

Burst Bitset
F[I][J] Indicates if S[1..I] has a suffix to match t[1..j]
So suppose S[i+1] can match t[s], make f[i+1][s] | = F[i][s-1]
So the preprocessing sets where each character can match the T, set to [C]
So f[i]= ((f[i-1]<<1) | ( 1<<1)) & Mat[s[i]]
Just make a match on the mat.
Time complexity: O (| s| | T|/32)

Code
#include <cstdio> #include <bitset> #include <cstring> #include <algorithm> #define LL long long#    Define GC GetChar () #define PC Putchar#define LD long doubleinline int read () {int x = 0,f = 1;    char C = GC;    while (C < ' 0 ' | | c > ' 9 ') C = GC;    while (c <= ' 9 ' && C >= ' 0 ') x = x * ten + C-' 0 ', C = GC; return x * f;}     void print (int x) {if (x >=) print (X/10); PC (x 10 + ' 0 ');  } const int MAXN = 100007; Char S[MAXN],T[MAXN];  std::bitset<maxn>mat[30],ans;      int main () {scanf ("%s%s", S + 1,t + 1);      int n = strlen (s + 1), M = strlen (t + 1);      for (int i = 1;i <= n;++ i) mat[s[i]-' A '].set (i);      Ans.set ();      for (int i = 1;i <= m;++ i) if (t[i]! = '? ') ans &= (mat[t[i]-' a '] >> (i-1));      int cnt = 0;      for (int i = 1;i <= n-m + 1;++ i) if (ans[i] = = 1) cnt + +;       Print (CNT);     PC (' \ n ');   for (int i = 1;i <= n-m + 1;++ i) if (ans[i] = = 1) print (i-1), PC (' \ n ');   return 0;   }

bzoj4503: Two strings of Bitset

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.