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) ...
随机推荐
- echarts 使用问题
总结下使用echarts的使用echarts 真的很好! 1 折线图line 1)有时出现赋值后,坐标轴显示数量比应该显示的少,是因为 显示不开,导致部分不显示(可通过调整字体大小等方式解决) 2) ...
- 无法跨越程序集边界使用程序集“DataCheck, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中的类型“List<ILayer>”,因为该类型有一个为嵌入互操作类型的泛型类型参数
主窗体: FrmDataInspect f2 = new FrmDataInspect(listMapControl1Lyr); f2.Show(); 弹出的窗体: 应该改为: gListMapLyr ...
- 提取json响应结果值_后置处理器JSON Extractor
Json响应格式 json串中{}表示对象,[]表示数组 JSON Extractor使用json path表达式匹配,可以一次取多个变量值. $表示响应的根对象. 取子对象或对象的属性用. 取数组里 ...
- 使用反向代理的http的请求流程
此文章主要为刚接触反向代理的小伙伴梳理请求流程,以便更好的理解反向代理是何时工作的 流程 由于浏览器是有缓存的,所以本地的hosts文件的信息也会在浏览器端缓存 当客户端发起一个新的请求(例如:输入的 ...
- Android SDK下载和更新失败的如何解决
一.scenario: 在部署Appium环境搭建时,安装SDK Manager.exe,遇到Android SDK下载更新失败. 报错信息如下图: Failed to fetch URL https ...
- .net core开发工具与SDK
一.开发工具 开发工具使用Visual Studio 2017 下载官网:https://visualstudio.microsoft.com/zh-hans/vs/ 相关的安装已经有很多文章介绍过, ...
- aws的安全组
aws有安全组来控制进入和去除的规则. 入站:就是外网访问你出站:就是你访问外网用户可以创建入站和出站规则,从而阻挡或者允许特定程序或者端口进行连接;用户可以将规则应用于一组程序.端口或者服务,也可以 ...
- UIDatePicker封装
#import <UIKit/UIKit.h> #import <objc/runtime.h> @protocol datePickerViewDelegate <NS ...
- jmeter报错:内存溢出
使用jmeter进行压力测试时,经常会遇到内存溢出错误: 2018-08-28 09:01:26,686 ERROR o.a.j.JMeter: Uncaught exception: java.la ...
- kafka4 副本机制
概述 每个分区有n个副本,可以承受n-1个节点故障. 每个副本都有自己的leader,其余都是follower. zk中存放分区的leader和 follower replica的信息.(get /b ...