状态是DAG,因此方案用dp统计,dp[i] = sum(dp[i+len(x)]),x是以i开头的前缀且是单词,关键在于快速判断一个前缀是不是单词,可用Trie。

每一次转移的复杂度是O(maxlen),maxlen是单词的最长长度。

#include<bits/stdc++.h>
using namespace std; const int maxn = *//4000*98+26*26+26+1
,sigma_size = ; int ch[maxn][sigma_size];
bool vis[maxn];
int nd_cnt; const int LEN = 3e5+, mod = ;
char str[LEN];
int d[LEN]; void init()
{
nd_cnt = ; memset(ch[],,sizeof(ch[]));
} void add(char *s)
{
int u = ;
int n = strlen(s);
for(int i = ; i < n; i++){
int c = word[i]-'a';
if(!ch[u][c]){
memset(ch[nd_cnt],,sizeof(ch[nd_cnt]));
vis[nd_cnt] = false;
ch[u][c] = nd_cnt++;
}
u = ch[u][c];
}
vis[u] = true;
} int main()
{
//freopen("in.txt","r",stdin);
char word[];
int kas = ;
while(gets(str)){
init();
int S; scanf("%d\n",&S);
while(S--){
gets(word);
add(word);
}
int n = strlen(str);
d[n] = ;
for(int cur = n-; cur >= ; cur--){
int u = ; d[cur] = ;
for(int i = cur; i < n; i++){
int c = str[i]-'a';
if(!ch[u][c]) break;
u = ch[u][c];
if(vis[u]) d[cur] += d[i+];
}
d[cur] %= mod;
}
printf("Case %d: %d\n",++kas,d[]);
}
return ;
}

UVALive 3942 Remember The Word (Tire)的更多相关文章

  1. UVALive 3942 Remember the Word(字典树+DP)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  2. UVALive - 3942 Remember the Word (Trie + DP)

    题意: 给定一篇长度为L的小写字母文章, 然后给定n个字母, 问有多少种方法用这些字母组成文章. 思路: 用dp[i]来表达[i , L]的方法数, 那么dp[i] 就可以从dp[len(x) + i ...

  3. 【暑假】[实用数据结构]UVAlive 3942 Remember the Word

    UVAlive 3942 Remember the Word 题目: Remember the Word   Time Limit: 3000MS   Memory Limit: Unknown   ...

  4. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  5. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  6. C#操作Office.word(二)

    在上一篇文章"C#操作Office.word(一)"中我们讲述了如何使用VS2010引用COM中Miscrosoft Word 14.0 Object Library实现创建文档, ...

  7. UVALive 3942 Remember the Word 字典树+dp

    /** 题目:UVALive 3942 Remember the Word 链接:https://vjudge.net/problem/UVALive-3942 题意:给定一个字符串(长度最多3e5) ...

  8. 最全总结 | 聊聊 Python 办公自动化之 Word(中)

    1. 前言 上一篇文章,对 Word 写入数据的一些常见操作进行了总结 最全总结 | 聊聊 Python 办公自动化之 Word(上) 相比写入数据,读取数据同样很实用! 本篇文章,将谈谈如何全面读取 ...

  9. 最全总结 | 聊聊 Python 办公自动化之 Word(下)

    1. 前言 关于 Word 文档的读写,前面两篇文章分别进行了一次全面的总结 最全总结 | 聊聊 Python 办公自动化之 Word(上) 最全总结 | 聊聊 Python 办公自动化之 Word( ...

随机推荐

  1. php封装pdo操作数据的工具类

    <?php header("Content-Type:text/html;charset=utf-8"); class PdoMysql{ public static $co ...

  2. mui 关闭当前窗口

    在提交表单的时候,我们都需要关闭表单.需要关闭当前打开的窗口. bit.alert('提交成功' + (result.category.needAudit ? ",请耐心等待管理员审核信息后 ...

  3. ue4 svn备份目录

    http://blog.csdn.net/sh15285118586/article/details/55737480 UE4工程文件备份目录有:Config.Content.Plugins.Sour ...

  4. python入门的基本历程

    Python入门 1.1环境安装 python官网下载,安装之后添加环境变量. 1.2集成开发环境 PyCharm官网下载,安装后:new project-﹥pure python 设置python解 ...

  5. DDD 落地的具体思路

    学习 DDD 的朋友有两种,一种是看 DDD 经典书籍 <领域驱动设计:软件核心复杂性应对之道>完全看不懂,第二种是看啥都懂,都觉得有道理,但总是落不了地. 我们总结一下我们自己落地的思路 ...

  6. PJzhang:子域名爆破工具wydomain(猪猪侠)

    猫宁!!! 参考链接:https://www.secpulse.com/archives/53182.html https://www.jianshu.com/p/65c85f4b7698 http: ...

  7. 使用tcpdump抓取EOS帐户创建与交易数据

    基本环境配置 EOS 版本:1.0.1(2018-06-04更新)   节点nodeos http监听端口:127.0.0.1:8888 本地钱包keosd http监听端口:127.0.0.1:89 ...

  8. Java基础笔记(四)——命名规则、数据类型

    标识符即Java程序中需要自定义的名称,如变量名.方法名.类名.包名.工程名等. 标识符的命名规则: 1.可由字母.数字.下划线(_)和美元符($)组成,不能以数字开头. 2.严格区分大小写. 3.不 ...

  9. 解决 程序报 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 错误

    调试程序出现如下错误: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Default ...

  10. sublime配置nodejs运行调试js

    node.js调试javascript的配置 1. 首先到 nodejs.org 下载 Node.js 安装包并安装.2. 打开 Sublime Text 编辑器.选择菜单 Tools --> ...