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

思路:字典树(显然)+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. ppshu

    全部书籍已经下载完毕! http://3cvpkfx4gdnkcduj.onion/ https://3cvpkfx4gdnkcduj.onion.cab/ https://3cvpkfx4gdnkc ...

  2. 单例模式Java“完美”实现

    我们通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问,从而方便对实例个数的控制并节约系统资源.如果希望在系统中某个类的对象只能存在一个,单例模式是最好的解决方案. public cl ...

  3. CloudTest 事务监控:千呼万唤始出来

    SmartBear 数据表明,如果 Amazon 的加载时间延长 1 秒,那么一年就会减少 16 亿美元的营收.用户与网站互动的过程中,如果加载时间超过3秒,57% 的用户会流失.可见,网站的加载时间 ...

  4. 跨平台Unicode与UTF8互转代码

    参考来源:http://blog.csdn.net/flying8127/article/details/1598521 在原来原基础上,将代码整理,并加强安全性. 并按照WindowsAPI设计, ...

  5. Android 显示大图片

    主要的代码如下: BitmapFactory.Options options = new BitmapFactory.Options(); //图片解析配置 options.inJustDecodeB ...

  6. [博弈]ZOJ3591 Nim

    题意: 给了一串数,个数不超过$10^5$,这串数是通过题目给的一段代码来生成的 int g = S; ; i<N; i++) { a[i] = g; ) { a[i] = g = W; } = ...

  7. java jdk自带程序分析(内存分析/线程分析)

    周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令. 1.1.Jstack 1.1   jstack能得到运行jav ...

  8. java中List集合及其遍历详解

    1. 首先List<E>集合继承与Collection<E>,是一个接口. ①  Collection (集合框架是JDK1.2版本出现的) ②   list:是有序的,元素可 ...

  9. SPRING IN ACTION 第4版笔记-第九章Securing web applications-009-拦截请求()

    一. 对特定的请求拦截 For example, consider the requests served by the Spittr application. Certainly, thehome ...

  10. WinAPI你知道多少?!(上千个,好多都没见过)

    http://www.cnblogs.com/vanver/archive/2013/06/13/NO-2013_06_13pm.html 播客开篇,讲讲废话:本篇播客只是推荐给热与钻研的同学们... ...