uvalive 3490 解法二 AC自动机 + 高斯消元

/****
AC自动机 + 高斯消元
AC自动机判断当前状态i通过j能到达的所有状态
E(i)表示当前状态为i,到最终状态的期望

E(i) = Sum(E(next[i][j])+1)/n;
最终结果就是E[0]
******/

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
using namespace std;
#define maxn 500010

struct Trie{
    int next[maxn][26],fail[maxn],end[maxn];
    int root,L;

    int newNode(){
        for(int i=0;i<26;i++) next[L][i] = -1;
        end[L++] = 0;
        return L-1;
    }

    void init(){
        L = 0;
        root = newNode();
    }

    void insert(char str[]){
        //printf("insert:%s\n",str);
        int len = strlen(str);
        int now = root;
        for(int i=0;i
      
      
       
        que;
        fail[root] = root;
        for(int i=0;i<26;i++){
            if( next[root][i] == -1){
                next[root][i] = root;
            }else{
                fail[next[root][i]] = root;
                que.push(next[root][i]);
            }
        }
        while(!que.empty()){
            int now = que.front();
            que.pop();
            for(int i=0;i<26;i++){
                int t = next[now][i];
                if(t==-1){
                    next[now][i] = next[fail[now]][i];
                }else{
                    fail[t] = next[fail[now]][i];
                    que.push(t);
                }
            }
        }
    }

    void debug(){
        for(int i=0;i
       
       
         = 0; i--) { for(int j = i + 1; j < var; j++) x[i] -= x[j]*a[i][j]; x[i] /= a[i][i]; } return x[0]; } /// char buf[20]; int n; void getEquation(){ var = ac.L; equ = 0; memset(a,0,sizeof(a)); for(int i=0;i 
         
       
      
      
     
     
    
    
   
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值