Regular Number
题意:一个仅由0~9字符组成的字符串x有n个字符,i位置可选择的字符有ai种,给出一个长串s,找出x能构成的s的所有子串;
思路:用对0~9每个字符建一个长度为n的bitset,若该字符在i位置可供选择,就将对应位置置为1;
再用一个新的bitset与s对应;
#include <bits/stdc++.h>
using namespace std;
bitset<1005> b[10];
bitset<1005> ans;
char str[5000010];
int main(){
int n;
while(~scanf("%d", &n)){
for(int i=0; i<10; i++) b[i].reset();
ans.reset();
int a, x;
for(int i=0; i<n; i++){
scanf("%d", &a);
while(a--){
scanf("%d", &x);
b[x].set(i);
}
}
scanf("%s", str);
int len=strlen(str);
for(int i=0; i<len; i++){
ans=ans<<1;
ans[0]=1;
ans=ans&b[str[i]-'0'];
if(ans[n-1]==1){
char temp=str[i+1];
str[i+1]='\0';
printf("%s\n", str+i-n+1);
str[i+1]=temp;
}
}
}
return 0;
}