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_day5

    32题...今天颓了不想再写了

  2. 【BZOJ 2553】[BeiJing2011]禁忌 AC自动机+期望概率dp

    我一开始想的是倒着来,发现太屎,后来想到了一种神奇的方法——我们带着一个既有期望又有概率的矩阵,偶数(2*id)代表期望,奇数(2*id+1)代表概率,初始答案矩阵一列,1的位置为1(起点为0),工具 ...

  3. [fzu 2271]不改变任意两点最短路至多删的边数

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2271 题目中说每条边的边权都是[1,10]之间的整数,这个条件非常关键!以后一定要好好读题啊…… 做10次循环 ...

  4. Codeforces Round #525 (Div. 2)A. Ehab and another construction problem

    A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找 ...

  5. bzoj4589 FWT xor版本

    4589: Hard Nim Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 865  Solved: 484[Submit][Status][Disc ...

  6. 使用fuser查询文件、目录、socket端口的占用进程

    fuser可用于查询文件.目录.socket端口和文件系统的使用进程 1.查询文件和目录使用者 fuser最基本的用法是查询某个文件或目录被哪个进程使用: # fuser -v ./          ...

  7. ShareSDK入门指南:Android 10分钟快速集成

    ShareSDK 官方已提供Android 快速集成教程,以官方教程为参考,本文重点指导大家在集成中遇到的问题. Android 快速集成官方教程:http://wiki.mob.com/Androi ...

  8. 数据结构之DFS与BFS

    深度搜索(DFS) and  广度搜索(BFS) 代码如下: #include "stdafx.h" #include<iostream> #include<st ...

  9. 接口认证方式:Bearer Token

    因为HTTP协议是开放的,可以任人调用.所以,如果接口不希望被随意调用,就需要做访问权限的控制,认证是好的用户,才允许调用API. 目前主流的访问权限控制/认证模式有以下几种: 1),Bearer T ...

  10. JavaScript中cookie使用

    转自:http://www.cnblogs.com/yjzhu/archive/2012/11/26/2789032.html 一.什么是 cookie? cookie 就是页面用来保存信息,比如自动 ...