UVAL 3942 Remember the Word(递推+Trie)
Remember the Word
【题目链接】Remember the Word
【题目类型】递推+Trie
&题解:
蓝书P209,参考的别人公开代码
&代码:
#include <cstdio>
#include <bitset>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn= 4005*100 +7,sigmaSize=26;
int ch[maxn][sigmaSize],sz,K;
bool vis[maxn];
void init() {sz=1; memset(ch[0],0,sizeof(ch[0]));}
void add(char *s) {
int u=0;
for(int i=0; s[i]; i++) {
int c=s[i]-'a';
if(!ch[u][c]) {
memset(ch[sz],0,sizeof(ch[sz]));
vis[sz]=false;
ch[u][c]=sz++;
}
u=ch[u][c];
}
vis[u]=true;
}
const int LEN=3e5+5,mod=20071027;
char str[LEN];
int d[LEN];
int main() {
freopen("E:1.in","r",stdin);
char word[120];
while(~scanf("%s",str)) {
init();
int S; scanf("%d",&S);
while(S--) {
scanf("%s",word);
add(word);
}
int n=0;
while(str[n]) d[n++]=-1;
d[n]=1;
for(int cur=n-1; cur>=0; cur--) {
int u=0;
d[cur]=0;
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[cur]+d[i+1])%mod;
}
}
printf("Case %d: %d\n",++K,d[0]);
}
return 0;
}
UVAL 3942 Remember the Word(递推+Trie)的更多相关文章
- UVA - 1401 | LA 3942 - Remember the Word(dp+trie)
https://vjudge.net/problem/UVA-1401 题意 给出S个不同的单词作为字典,还有一个长度最长为3e5的字符串.求有多少种方案可以把这个字符串分解为字典中的单词. 分析 首 ...
- Trie + DP LA 3942 Remember the Word
题目传送门 题意:(训练指南P209) 问长字符串S能由短单词组成的方案数有多少个 分析:书上的做法.递推法,从后往前,保存后缀S[i, len-1]的方案数,那么dp[i] = sum (dp[i+ ...
- UVALive - 3942 Remember the Word (Trie + DP)
题意: 给定一篇长度为L的小写字母文章, 然后给定n个字母, 问有多少种方法用这些字母组成文章. 思路: 用dp[i]来表达[i , L]的方法数, 那么dp[i] 就可以从dp[len(x) + i ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- UVA 1401 Remember the Word(用Trie加速动态规划)
Remember the Word Neal is very curious about combinatorial problems, and now here comes a problem ab ...
- 第46套题【STL】【贪心】【递推】【BFS 图】
已经有四套题没有写博客了.今天改的比较快,就有时间写.今天这套题是用的图片的形式,传上来不好看,就自己描述吧. 第一题:单词分类 题目大意:有n个单词(n<=10000),如果两个单词中每个字母 ...
- 【暑假】[实用数据结构]UVAlive 3942 Remember the Word
UVAlive 3942 Remember the Word 题目: Remember the Word Time Limit: 3000MS Memory Limit: Unknown ...
- LA 3942 Remember the Word(前缀树&树上DP)
3942 - Remember the Word Neal is very curious about combinatorial problems, and now here comes a pro ...
- UVALive 3942 Remember the Word 字典树+dp
/** 题目:UVALive 3942 Remember the Word 链接:https://vjudge.net/problem/UVALive-3942 题意:给定一个字符串(长度最多3e5) ...
随机推荐
- [No0000115]打开Excel2016提示内存或磁盘空间不足的解决方法
症状: 法一:右键文件,并 解除锁定: 法二: 在系统的服务中查看Windows Firewall服务 和Windows Update服务是否开启,如果没有开启就把他们启动一下. 1.在桌面的[计算机 ...
- [No0000DC]C# FileHelper 本地文件、文件夹操作类封装FileHelper
using System; using System.Diagnostics; using System.IO; using System.Text; using Shared; namespace ...
- java高级精讲之高并发抢红包~揭开Redis分布式集群与Lua神秘面纱
java高级精讲之高并发抢红包~揭开Redis分布式集群与Lua神秘面纱 redis数据库 Redis企业集群高级应用精品教程[图灵学院] Redis权威指南 利用redis + lua解决抢红包高并 ...
- Sticks POJ - 1011 少林神棍 dfs四次剪枝
http://poj.org/problem?id=1011 题意:若干根棍子被截成小段的木棒,现在给你这些木棒,问最短可以拼出的棍子长度. 题解:搜索,dfs(r,m) 二个参数分别代表还剩r个木棒 ...
- 配置llama实现impala on yarn-验证未通过,仅以此文作为参考
以下内容采自网络,目前验证未通过,仅以此作为参考: 简介:早期的Impala版本中,为了使用Impala,我们通常会在以Client/Server的结构在各个集群节点启动impala-server.i ...
- 使用shell删除目录下几天前生成文件方法
find /dbfdumpdir/*full* -mtime +21 -exec rm -rf {} \; 这个shell可以删除目录/dbfdumpdir下面21天前生成的,文件名包含full的文件 ...
- linux 记录所有用户bash操作日志
记录所有用户登录系统的任何操作日志,以便有据可查. 1.编辑 /etc/profile文件. 1 # vim /etc/profil 2. 在其后添加如下内容 1 2 3 4 5 6 7 8 ...
- C语言保证,0永远不是有效的数据地址,因此,返回址0可用来表示发生的异常事件
C语言保证,0永远不是有效的数据地址,因此,返回址0可用来表示发生的异常事件
- [troubleshoot][automake] automake编译的时候发生死循环
在某台特有设备上,编译dssl工程时,竟然发生了死循环. https://github.com/tony-caotong/libdssl 错误日志如下: checking zlib.h presenc ...
- bzoj 2563 [2012国家集训队Round 1 day2] 阿狸和桃子的游戏 贪心
正解:贪心 解题报告: 链接在这儿! 知道解法之后会jio的好像很简单的样子……其实挺难想到的QAQ 不过大佬讲了方法之后还是懂了 有一个很神仙的想法就是,你可以理解为每个点周围的边都有半个是自己的, ...