link

题意:

给一个模板串s和n个模式串,每个模式串有$a_i$种可取的串。现在要将n个模式串每个任取一种它可取的串,连接起来,记为串t,那么这种连接方式对答案的贡献为t在s中出现的次数。问所有连接方式的贡献之和。

$n\leq 100,|S|\leq 10^4.$

题解:

设f[i][j]表示使用前i个模式串,匹配前j位的贡献。对每个模式串的每种可能转移,使用hash判断是否匹配。

复杂度$\mathcal{O}(|S|\times \sum a_i)$。

花絮:

今天我生日> <,生快啦。

code:

 #include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
char gc(){
static char buf[],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,,,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
char ch=gc();ll x=;int op=;
for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-;
for (;isdigit(ch);ch=gc()) x=(x<<)+(x<<)+ch-'';
return x*op;
}
#define N 10005
#define M 105
#define mod 1000000007
#define seed 233
#define happy_birthday 20180731
int n,m,now,f[][N],h[N],pw[N],ans;//f[i][j]:使用前i个字符串,匹配前j位的匹配方案数
char str[N],s[N];
void upd(int &x,int y){x+=y;x-=x>=mod?mod:;}
void init(){
h[]=;pw[]=;
rep (i,,n){
h[i]=((ll)h[i-]*seed+str[i])%happy_birthday;
pw[i]=(ll)pw[i-]*seed%happy_birthday;
}
}
int cal(int x,int y){
return (h[y]+happy_birthday-(ll)h[x-]*pw[y-x+]%happy_birthday)%happy_birthday;
}
int main(){
m=read();
scanf("%s",str+);n=strlen(str+);
init();
now=;rep (i,,n) f[][i]=;//可以从任意位置开始
while (m--){
now^=;memset(f[now],,sizeof(f[now]));
for (int k=read();k;k--){
scanf("%s",s+);int l=strlen(s+);
int hsh=;rep (i,,l) hsh=((ll)hsh*seed+s[i])%happy_birthday;
rep (i,,n-l+)
if (cal(i,i+l-)==hsh) upd(f[now][i+l-],f[now^][i-]);
}
}
rep (i,,n) upd(ans,f[now][i]);
printf("%d\n",ans);
return ;
}

最新文章

  1. 关于tomcat内路径跳转的一些思考
  2. LR12.53—第4课:准备Vuser脚本进行负载测试
  3. 三分钟玩转jQuery.noConflict()
  4. ios crash 日志分析
  5. visual studio installer制作安装包——Installer 类
  6. php模式设计之 单例模式
  7. SQL语句:SQLwhile(0=0)与while @@fetch_status=0.
  8. Css基础-介绍及语法
  9. JavaScript eval() 为什么使用eval()是一个坏主意 什么时候可以使用eval()
  10. referencedColumnName
  11. 用python对比两张图片的不同
  12. Eclipse使用Maven创建Web时错误:Could not resolve archetype
  13. Core Graphices 获取上下文
  14. Could not open JDBC Connection for transaction
  15. SQL记录-PLSQL包
  16. 开源项目PullToRefresh详解(四)——PullToRefreshListView和ViewPager的结合使用
  17. 20172311『Java程序设计』课程 结对编程练习_四则运算第一周阶段总结
  18. 关于表单中Readonly和Disabled
  19. vue 隐藏滚动条
  20. python中快速获取本地时区当天0点时间戳的一种方法

热门文章

  1. VC拷贝字符串到剪切板
  2. 第三讲:ifconfig:最熟悉又陌生的命令行
  3. 南邮综合题writeup
  4. 37 - 网络编程-UDP编程
  5. Linux 用户态与内核态的交互【转载】
  6. springMVC中ajax的实现
  7. Dev Express 安装
  8. gradle-4.1-rc-1-all.zip gradle-4.1-rc-2-all.zip 免费下载(百度网盘)
  9. PlantUML&mdash;&mdash;3.Graphviz的安装
  10. Linux打补丁的一些问题