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. 【BZOJ 1724】[Usaco2006 Nov]Fence Repair 切割木板 堆+贪心

    堆对于stl priority_queue ,我们自己定义的类自己重载<,对于非自定义类我们默认大根堆,如若改成小根堆则写成std::priority<int,vector<int& ...

  2. How do I see what character set a database / table / column is in MySQL?

    Q: How do I see what the character set that a MySQL database, table and column are in? Is there some ...

  3. poj 2378 Tree Cutting 树形dp

    After Farmer John realized that Bessie had installed a "tree-shaped" network among his N ( ...

  4. Kafka自我学习-报错篇

    1. kafka启动出现:Unsupported major.minor version 52.0 错误,  具体的错误输出: Exception in thread "main" ...

  5. [CVPR2017]Online Video Object Segmentation via Convolutional Trident Network

    基于三端卷积网络的在线视频目标分割 针对半监督视频目标分割任务,作者采取了和MaskTrace类似的思路,以optical flow为主. 本文亮点在于: 1. 使用共享backbone,三输出的自编 ...

  6. css3 新旧伸缩盒的异同

    由于不需要理会IE浏览器,伸缩盒(flexible box)移动端开发中非常好用! 工作中使用APICLOUD开发手机App,老板要求兼容到安卓2.3(新版的需要安卓4.4以上),所以一直使用的是旧版 ...

  7. NSMutableArray遍历删除注意事项

      for (int i = 0; i < [array count]; i++) { [array removeObjectAtIndex:i]; } 上面的遍历由于在remove操作之后ar ...

  8. CSS3 渐变(Gradients)

    参考: http://www.runoob.com/css3/css3-gradients.html CSS3 渐变(gradients)可以让你在两个或多个指定的颜色之间显示平稳的过渡. 以前,你必 ...

  9. guake 3.4发布,支持切分窗口

    guake是一款下拉式终端,美观实用. 近日发布了3.4版本,在3.4版本中支持了切分窗口功能.如图所示,还是比较实用的一个功能. 目前ubuntu仓库中还未更新,需要使用pip安装,或者自行从源码编 ...

  10. json相关注解和序列化与反序列化

    使用jackson进行序列化时,往往会遇到后台某个实体对象的属性为null,当序列化成json时对应的属性也为null,可以用以下的注解方式完成当属性为null时不参与序列化: @JsonSerial ...