POJ 1625 Censored! AC自动机+DP+高精度 *

题目地址:http://poj.org/problem?id=1625

一样是拿母串在trie上搜索,且不经过危险节点

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
struct BigInteger{
    int num[300];  
    int len;
    BigInteger(){  
        memset(num,0,sizeof(num)); len=0;  
    }  
    void output(){  
        for(int i=len-1;i>=0;i--)  
            cout< idx;
BigInteger d[50+5][100+5];
int nNode,N,M,P;
//d[i][j]要长度为i到达节点j,也即是tree[j] 字符串个数 
void Insert(Node* root,char* s)
{
	for(int i=0;s[i];i++)
	{
		if(root->pChilds[idx[s[i]]]==NULL)
			root->pChilds[idx[s[i]]]=tree+nNode++;
		root=root->pChilds[idx[s[i]]];
	}
	root->bBadNode=true;
}
void BuildDfa()
{
	for(int i=0;i Q;
	Q.push(tree+1);
	while(!Q.empty())
	{
		Node* root=Q.front(); Q.pop();
		for(int i=0;ipChilds[i];
			if(p==NULL) continue;
			Node* pPrev=root->pPrev;
			while(pPrev!=NULL){
				if(pPrev->pChilds[i]!=NULL){
					p->pPrev=pPrev->pChilds[i];
					if(p->pPrev->bBadNode) p->bBadNode=true;
					break;
				}
				else pPrev=pPrev->pPrev;
			}
			Q.push(p);
		}
	}
}
int main()
{
	scanf("%d%d%d",&N,&M,&P);
	scanf("%s",str);
	for(int i=0;str[i];i++) idx[str[i]]=i;
	nNode=2;
	for(int i=0;ipChilds[k]!=NULL){
					if(pPrev->pChilds[k]->bBadNode) break;
					int son=pPrev->pChilds[k]-tree;
					d[i+1][son]=d[i+1][son]+d[i][j];
					break;
				} 
				pPrev=pPrev->pPrev;
			} 
		}	
	}
	
	BigInteger result[105];
	int k=0;
    result[0].num[result[0].len++]=0;
    for(int i=1;i


你可能感兴趣的:(POJ+百练,字符串:AC自动机)