Link:

LA 3942 传送门

Solution:

感觉自己字符串不太行啊,要加练一些蓝书上的水题了……

$Trie$+$dp$

转移方程:$dp[i]=sum\{ dp[i+len(x)+1]\} (x为从第i位开始的字符串的前缀)$

计算一个字符串前缀的多模式匹配在$Trie$树上跑一遍就行啦!

Code:

#include <bits/stdc++.h>

using namespace std;
const int MAXN=4e5+,MOD=;
bool vis[MAXN];
char s[MAXN],tmp[MAXN];
int T,n,ch[MAXN][],dp[MAXN],l,len,cnt=,rt=; int main()
{
while(~scanf("%s",s+))
{
memset(ch,,sizeof(ch));memset(dp,,sizeof(dp));
memset(vis,false,sizeof(vis)); T++;len=strlen(s+);
scanf("%d",&n);cnt=;
for(int i=;i<=n;i++)
{
scanf("%s",tmp+);l=strlen(tmp+);
int cur=rt;
for(int j=;j<=l;j++)
{
if(!ch[cur][tmp[j]-'a'])
ch[cur][tmp[j]-'a']=++cnt;
cur=ch[cur][tmp[j]-'a'];
}
vis[cur]=true;
} dp[len+]=;
for(int i=len;i>=;i--)
{
int cur=rt;
for(int j=i;j<=len;j++)
{
if(!ch[cur][s[j]-'a']) break;
cur=ch[cur][s[j]-'a'];
if(vis[cur]) (dp[i]+=dp[j+])%=MOD;
}
}
printf("Case %d: %d\n",T,dp[]);
}
return ;
}

[LA 3942] Remember the Word的更多相关文章

  1. LA 3942 Remember the Word(前缀树&树上DP)

    3942 - Remember the Word Neal is very curious about combinatorial problems, and now here comes a pro ...

  2. Trie + DP LA 3942 Remember the Word

    题目传送门 题意:(训练指南P209) 问长字符串S能由短单词组成的方案数有多少个 分析:书上的做法.递推法,从后往前,保存后缀S[i, len-1]的方案数,那么dp[i] = sum (dp[i+ ...

  3. UVA - 1401 | LA 3942 - Remember the Word(dp+trie)

    https://vjudge.net/problem/UVA-1401 题意 给出S个不同的单词作为字典,还有一个长度最长为3e5的字符串.求有多少种方案可以把这个字符串分解为字典中的单词. 分析 首 ...

  4. LA 3942 - Remember the Word 字典树+DP

    看题传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  5. LA 3942 - Remember the Word (字典树 + dp)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

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

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

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

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

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

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

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

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

随机推荐

  1. 如何用JavaScript做一个可拖动的div层

    可拖动的层在Web设计中用处很多,比如在某些需要自定义风格布局的应用中,控件就需要拖动操作,下面介绍一个,希望可以满足你的需求,顺便学习一下可拖动的层是如何实现的. 下面是效果演示: 这个DIV可以移 ...

  2. 用@Component注解代替@Configuration注解,定义bean

    package com.timo.entity; import org.springframework.beans.factory.annotation.Value; import org.sprin ...

  3. centos7 mysql cluster集群搭建基于docker

    1.准备 mn:集群管理服务器用于管理集群的其他节点.我们可以从管理节点创建和配置集群上的新节点.重新启动.删除或备份节点. db2/db3:这是节点间同步和数据复制的过程发生的层. db4/db5: ...

  4. linux下将jpg,jpeg格式转为PDF

    1.安装imagemagick(用其中的convert)和gthumb     sudo apt-get install imagemagick gthumb 2.将tiff图片转换为png或jpeg ...

  5. 记录一发wm_concat()函数排序的问题

    需求:需要将列转行之后的工序按照待执行工序号排序,如果一样按工序号排 解决方法如下: select part_no, max(ywggx) ywggx from(select mt.part_no , ...

  6. SpringMVC学习 -- REST

    REST:表现层状态转化. REST 是目前最流行的一种互联网软件架构.他结构清晰.符合标准.易于理解.扩展方便 , 所以正得到越来越多网站的采用. 状态转化:浏览器 form 表单只支持 GET 和 ...

  7. 解析 Array.prototype.slice.call(arguments,0)

    Array.prototype.slice.call(arguments,0) 经常会看到这段代码用来处理函数的参数 网上很多复制粘帖说:Array.prototype.slice.call(argu ...

  8. CMOS与BIOS

    BIOS与CMOS的区别 : 1. 所谓BIOS,实际上就是微机的基本输入输出系统(Basic Input-Output System),其内容集成在微机主板上的一个ROM芯片上,主要保存着有关微机系 ...

  9. Spring - IoC(9): @Resoure & @Autowired

    @Resource 和 @Autowired 都是用来装配依赖的,它们之间有些异同. @Resoure @Resource 是 JSR-250 规范的注解. @Resource 可以标注在字段.方法上 ...

  10. RabbitMQ消息队列(二): 工作队列

    1. 工作队列: 对于资源密集型任务,我们等待其处理完成在很多情况下是不现实的,比如无法在http的短暂请求窗口中处理大量耗时任务, 为了达到主线程无需等待,任务异步执行的要求,我们可以将任务加入任务 ...