题意:告诉你一个母串和子串,能用多少种不同的方案组合出母串。

思路:字典树(显然)+DP

DP: dp[i]+=dp[j+1]  i<=j<=m-1,且i到j的字符串能在字典树中找到。也就等价dp[i]=1*dp[j+1]

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std; #define LL long long
const int maxn=*;
const int maxm=3e5+;
const int mod=;
struct Trie
{
int ch[maxn][];
int val[maxn];
int sz;
Trie()
{
sz=;
memset(ch[],,sizeof(ch[]));
}
int idx(char c)
{
return c-'a';
} void insert(char *s,int v)
{
int i,u=,n=strlen(s);
for(i=; i<n; i++)
{
int c=idx(s[i]);
if(!ch[u][c])
{
memset(ch[sz],,sizeof(ch[sz]));
val[sz]=;
ch[u][c]=sz++;
}
u=ch[u][c];
}
val[u]=v;
}
} e;
char str[maxm];
char a[];
LL dp[maxm];
int main()
{
int tt=;
while(scanf("%s",str)!=EOF)
{
int i,j,k,n,m,u;
scanf("%d",&n);
memset(e.ch[],,sizeof(e.ch[]));
e.sz=;
for(i=; i<n; i++)
{
scanf("%s",a);
e.insert(a,);
}
m=strlen(str);
memset(dp,,sizeof(dp));
dp[m]=;
for(i=m-; i>=; i--)
{
u=;
for(j=i; j<m; j++)
{
int c=e.idx(str[j]);
if(!e.ch[u][c])
break;
u=e.ch[u][c];
if(e.val[u])
dp[i]+=dp[j+];
}
dp[i]%=mod;
}
printf("Case %d: %lld\n",++tt,dp[]);
}
return ;
}

(Trie) uvalive 3942 Remember the word的更多相关文章

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

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

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

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

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

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

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

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

  5. UVALive - 3942 Remember the Word (Trie + DP)

    题意: 给定一篇长度为L的小写字母文章, 然后给定n个字母, 问有多少种方法用这些字母组成文章. 思路: 用dp[i]来表达[i , L]的方法数, 那么dp[i] 就可以从dp[len(x) + i ...

  6. UVALive 3942 Remember The Word (Tire)

    状态是DAG,因此方案用dp统计,dp[i] = sum(dp[i+len(x)]),x是以i开头的前缀且是单词,关键在于快速判断一个前缀是不是单词,可用Trie. 每一次转移的复杂度是O(maxle ...

  7. UVALive 3942 Remember the Word(字典树+DP)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. UVALive 3942 Remember the Word

    题意:给出一个由S个不同单词组成的字典和一个长字符串.把这个字符串分解成若干个单词的连接(单词可以重复 使用),有多少种方法? Sample Input abcd 4 a b cd ab Sample ...

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

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

随机推荐

  1. Nagios3完整配置文档

    第一章:简单快速安装nagios 1.1 准备软件包 在做安装之前确认要对该机器拥有root权限. 确认你安装好的linux系统上已经安装如下软件包再继续. Apache GCC编译器 GD库与开发库 ...

  2. 国外程序员整理的 C++ 资源大全

    摘要:C++是在C语言的基础上开发的一种集面向对象编程.泛型编程和过程化编程于一体的编程语言.应用较为广泛,是一种静态数据类型检查的,支持多重编程的通用程序设计语言. 关于 C++ 框架.库和资源的一 ...

  3. 一个HexToInt的C/C++函数

    int  BetterVenca25(char* hex){   int res=0;   for(;*hex;hex++)   {  int d=toupper(*hex);      if(d & ...

  4. Win32 DLL和MFC DLL 中封装对话框

    现在最常看见的关于DLL的问题就是如何在DLL中使用对话框,这是一个很普遍的关于如何在DLL中使用资源的问题.这里我们从Win32   DLL和MFC   DLL两个方面来分析并解决这个问题.     ...

  5. 程序自动生成Dump文件

    前言:通过drwtsn32.NTSD.CDB等调试工具生成Dump文件, drwtsn32存在的缺点虽然NTSD.CDB可以完全解决,但并不是所有的操作系统中都安装了NTSD.CDB等调试工具.了解了 ...

  6. strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签

    定义和用法 strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签. 语法 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. ...

  7. Get请求携带数据量的各种限制及解决办法、Post请求说明

    1.   Get请求携带数据量的各种限制及解决办法 Http Get方法提交的数据大小长度并没有限制,HTTP协议规范没有对URL长度进行限制.这个限制是特定的浏览器及服务器对它的限制. 到新公司处理 ...

  8. python之高性能网络编程并发框架eventlet实例

    http://blog.csdn.net/mingzznet/article/details/38388299 前言: 虽然 eventlet 封装成了非常类似标准线程库的形式,但线程和eventle ...

  9. 从iPhone4、iPhone5、iPhone6看手机外壳加工工艺进化史

    从iPhone4.iPhone5到iPhone6,苹果为我们推出了一代又一代新产品,让我们享受到最新的科技产品.每次不只是配置上的改变,苹果在工艺上也不断改变.下面就阐述一下我对这几款手机在设计和制造 ...

  10. No bean named 'transactionManager' is defined

    2016-10-20 23:27:17.771 INFO 7096 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quo ...