大二训练第一周 F - Remember the Word trie树加dp
来源:互联网 发布:网狐6603手机捕鱼源码 编辑:程序博客网 时间:2024/06/15 10:17
大白书上说 dp[i]=sum(dp[i]+dp[i+len(x)]初始化dp[len]=1然后递推回去
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈#include <map>#include <set>#include <queue>#include <cmath>#include <stack>#include <cctype>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rds(x) scanf("%s",x)#define rdc(x) scanf("%c",&x)#define ll long long int#define maxn 100005#define mod 20071027#define INF 0x3f3f3f3f //int 最大值#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define MT(x,i) memset(x,i,sizeof(x))#define PI acos(-1.0)#define E exp(1)#define MAX 26using namespace std;struct Trie{ bool v; Trie *next[MAX];};Trie *root;void creatTrie(char *str){ Trie *p=root,*q; int len=strlen(str); FOR(i,0,len-1){ int id=str[i]-'a'; if(p->next[id]==NULL){ q=(Trie *)malloc(sizeof(Trie)); FOR(i,0,MAX-1)q->next[i]=NULL; q->v=false; p->next[id]=q; p=p->next[id]; } else { p=p->next[id]; } } p->v=true;}int dp[300010];void qurey(int k,int m,char *str){ Trie *p=root; for(int i=k;i<m;++i){ int id=str[i]-'a'; if(p->next[id]!=NULL){ if(p->next[id]->v==true){ dp[k]=(dp[k]+dp[i+1])%mod; } p=p->next[id]; } else return; }}int doit(char *str){ int m=strlen(str);MT(dp,0);dp[m]=1; for(int i=m-1;i>=0;--i){ qurey(i,m,str); } return dp[0];}char str[300010];char t[4010];int cnt=1,q;int main(){ while(rds(str)!=EOF){ root=(Trie *)malloc(sizeof(Trie)); FOR(i,0,MAX-1)root->next[i]=NULL; rd(q);FOR(i,1,q){rds(t);creatTrie(t);} printf("Case %d: %d\n",cnt++,doit(str)); } return 0;}/*abcd4abcdab*/
0 0
- 大二训练第一周 F - Remember the Word trie树加dp
- [Trie树][dp] LA3942 Remember the Word
- UVA 1401 Remember the Word(DP+字典树Trie)
- Remember the Word,LA3942(Trie树+DP)
- Remember the Word - UVaLive 3942 Trie树+dp
- uva 1401Remember the Word(trie树+dp)
- (LA 3942)Remember the Word --DP+Trie树
- UVA 1401 Remember the Word(Trie树 套 DP)
- LA 3942 Remember the Word Trie树 DP
- [Trie树][dp] LA3942 Remember the Word 真·解法
- UVA 1401 Remember the Word(DP+字典树Trie)
- LA3942 remember the word trie+dp
- LA 3942 Remember the Word(Trie+DP)
- UVA 1401 - Remember the Word(Trie+DP)
- LA3942 Remember the Word(Trie+DP)
- uva 1401 Remember the Word ( Trie + DP )
- UVA 1401 Remember the Word (trie + dp)
- UVa 1401 Remember the Word(Trie+DP)
- SOJ 2785_Binary Partitions
- POJ 1844 Sum
- GTK+图形化应用程序开发学习笔记(九)—菜单
- 通过点击热区,有个href 跳到servlet,怎么把页面上的值传到servlet里面?
- 对象与json的转换
- 大二训练第一周 F - Remember the Word trie树加dp
- 常用排序算法的实现
- java反射机制
- 【leetcode】3.1 valid palindrome
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解(转)
- ECSHOP二次开发之心得体验
- va_start和va_end使用详解
- GTK+图形化应用程序开发学习笔记(十)—工具条
- 大二训练第一周 G - Keywords Search 艾斯atman