每个小单词的长度都是小于等于100的,这是个重要的突破口.

Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 300006
#define mod 20071027
using namespace std;
char str[maxn],wd[maxn];
int tag[maxn],n,f[maxn],m,cas;
struct TRIE{
#define SIGMA 30
int root,ch[maxn][SIGMA],cnt;
void init() {
root = cnt = 0;
memset(ch,0,sizeof(ch));
memset(tag,0,sizeof(tag));
memset(f,0,sizeof(f));
}
void ins(char s[]) {
int len = strlen(s),p = root;
for(int i = 0;i < len; ++i) {
if(!ch[p][s[i]-'a']) ch[p][s[i]-'a'] = ++cnt;
p = ch[p][s[i]-'a'];
}
tag[p] = 1;
}
void solve(int st){
int p = root;
for(int i = st;i <= m; ++i) {
p = ch[p][str[i]-'a'];
if(!p) break;
if(tag[p]) f[st] += f[i + 1],f[st] %= mod;
if(tag[p] && i == m) f[st] += 1;
}
}
}trie;
int main(){
//setIO("input");
while(scanf("%s",str) != EOF) {
scanf("%d",&n),trie.init(),m = strlen(str) - 1;
for(int i = 1;i <= n; ++i) scanf("%s",wd),trie.ins(wd);
for(int i = m;i >= 0; --i) trie.solve(i);
printf("Case %d: %d\n",++cas,f[0]);
}
return 0;
}

  

最新文章

  1. Amazon Interview | Set 27
  2. 备忘录--关于线程和IO知识
  3. Linux 网络编程详解十
  4. PHP多表取数据的代码优化
  5. Java异常与运行时异常,以及与线程的关系
  6. HDU1013Digital Roots
  7. [转]Response.AddHeader 文本下载
  8. &lt;&lt;深入Java虚拟机&gt;&gt;-第三章-垃圾收集器与内存分配策略-学习笔记
  9. javascript下用ActiveXObject控件替换word书签,将内容导出到word后打印第1/2页
  10. PHP设计模式笔记八:原型模式 -- Rango韩老师 http://www.imooc.com/learn/236
  11. github上传文件
  12. Python Scrapy项目创建(基础普及篇)
  13. mariadb安装
  14. Confluence 6 管理协同编辑 - 最大编辑者的限制
  15. MySQL学习笔记1(增删查改)
  16. centos7构建python2.7常用开发环境
  17. 看病要排队--hdu1873
  18. Python 不定参数函数
  19. VS2015快捷键及常用功能
  20. Mysql查询架构信息

热门文章

  1. iOS系统结构
  2. Eclipse安装不了AXIS2 Tool插件,总是找不到axis2 wizards的问题找到解决答案(转载)
  3. zabbix监控自身为监控机(server)
  4. Codeforces 679A Bear and Prime 100
  5. Tensorflow学习笔记——Summary用法
  6. webpack不打包指定的js文件
  7. echarts如何更改表格主题颜色
  8. Unity WWW类调用http
  9. 简单实现双向数据绑定mvvm。
  10. 微信小程序开发入门(一)