题意好难看懂的说。。。

  有限状态自动机DFA是这么一个有序组<Σ, U, s, T, phi>;Σ代表输入字符集,表示此自动机的工作范围;U代表所有的状态集合;s是初始状态;T是最终状态;phi代表转移函数,定义为phi : U × Σ → U。

  利用DFA进行字符串识别是要你做这么一件事情:The input of the automation is the string α over Σ. Initially the automation is in state s. Each step it reads the first character c of the input string and changes its state to phi(u, c) where u is the current state. After that the first character of the input string is removed and the step repeats. If when its input string is empty the automation is in the terminal state, it is said that it accepts the initial string α, in the other case it rejects it.

  然后无聊的出题人给他加入了一个,b的东西:Nonabsorbing Edges,直译不吸收边。Define function χ : U × Σ → {0, 1}. When making a transition from some state u with some character c, the leading character is removed from the input string only if χ(u, c) = 0. If χ(u, c) = 1, the input string is kept intact and next transition is performed with the new state and the same character.

  称这样的DFA为NADFA。

  NADFA接受字符串的条件是:such automation accepts some string α if after a number of steps it transits to the terminal state and the input string becomes empty.

  输入:第一行是字符集Σ。下来一行是k,表示状态数量。下一行第一个数字S代表初始状态,第二个数字L代表结束状态的数量,然后是L个数字,代表结束状态的编号。然后是一个k * |Σ|的矩阵,代表函数phi。然后再是一个同样大小的矩阵,代表函数X。最后是N。

  题目就是要你求能被此,b形式下的DFA(NADFA)接受的长度为N的字符串数量。


竟然是ASC#2的A题!!!
然后发现SGU200~2**都是ASC的原题。。不忍直视了。。以我的智商看来SGU都刷不了了。。
不过SGU200题说到做到,决不放弃!BZOJ用来专门练一些算法。

怎么搞??

DP是很显然的。用f[i][j]表示匹配到第i位时处在状态j的字符串数量。由于不可吸收边的存在,可以使用记忆化搜索预处理出状态的直接转移。

要用到高精度。。。压位大法好。。。

 //{HEADS
#define FILE_IN_OUT
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <string>
#define REP(i, j) for (int i = 1; i <= j; ++i)
#define REPI(i, j, k) for (int i = j; i <= k; ++i)
#define REPD(i, j) for (int i = j; 0 < i; --i)
#define STLR(i, con) for (int i = 0, sz = con.size(); i < sz; ++i)
#define STLRD(i, con) for (int i = con.size() - 1; 0 <= i; --i)
#define CLR(s) memset(s, 0, sizeof s)
#define SET(s, v) memset(s, v, sizeof s)
#define mp make_pair
#define pb push_back
#define PL(k, n) for (int i = 1; i <= n; ++i) { cout << k[i] << ' '; } cout << endl
#define PS(k) STLR(i, k) { cout << k[i] << ' '; } cout << endl
using namespace std;
void FILE_INIT(string FILE_NAME) {
#ifdef FILE_IN_OUT
#ifndef ONLINE_JUDGE
freopen((FILE_NAME + ".in").c_str(), "r", stdin);
freopen((FILE_NAME + ".out").c_str(), "w", stdout);
#endif
#endif
}
typedef long long LL;
typedef double DB;
typedef pair<int, int> i_pair;
const int INF = 0x3f3f3f3f;
//} const int maxn = + ;
const int maxl = + ;
const int maxm = + ;
const int maxc = ;
const int base = ; char sigma[maxc];
int Snum, Size, S, k, L, n;
int teminal_state[maxn], phi[maxn][maxc], chi[maxn][maxc], trans[maxn][maxc]; struct big_int {
int d[maxl];
int len;
big_int() {
CLR(d);
len = ;
}
big_int &operator += (const big_int &a) {
len = max(len, a.len);
REP(i, len) {
d[i] += a.d[i];
if(base < d[i]) {
d[i + ] += d[i] / base;
d[i] %= base;
}
}
for(; < d[ + len]; ++len);
return *this;
}
void print() {
printf("%d", d[len]);
for(int i = len - ; < i; --i) {
printf("%09d", d[i]);
}
puts("");
}
}f[maxn][maxm]; void dfs(int u, int c) {
if(chi[u][c] == ) {
trans[u][c] = u;
}
if(trans[u][c]) {
return;
}
trans[u][c] = -;
dfs(phi[u][c], c);
trans[u][c] = trans[phi[u][c]][c];
} int main() {
FILE_INIT(""); scanf("%s", sigma);
Size = strlen(sigma);
scanf("%d", &k);
scanf("%d %d", &S, &L);
REP(i, L) {
scanf("%d", &teminal_state[i]);
}
REP(i, k) {
REP(j, Size) {
scanf("%d", &phi[i][j]);
}
}
REP(i, k) {
REP(j, Size) {
scanf("%d", &chi[i][j]);
}
}
scanf("%d", &n);
REP(i, k) {
REP(j, Size) {
if(!trans[i][j]) {
dfs(i, j);
}
}
}
f[S][].d[] = ;
REPI(i, , n - ) {
REP(j, k) {
REP(c, Size) {
if(trans[j][c] > ) {
f[phi[trans[j][c]][c]][i + ] += f[j][i];
}
}
}
}
big_int ans;
REP(i, L) {
ans += f[teminal_state[i]][n];
}
ans.print(); return ;
}

201. Non Absorbing DFA的更多相关文章

  1. SGU 201 Non Absorbing DFA (DP)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个自动机,给出所有的转移,其中还有一个 ...

  2. AC自动机-算法详解

    What's Aho-Corasick automaton? 一种多模式串匹配算法,该算法在1975年产生于贝尔实验室,是著名的多模式匹配算法之一. 简单的说,KMP用来在一篇文章中匹配一个模式串:但 ...

  3. NFA与DFA

    正则表达式匹配,包含两个东西,一个是表达式,一个文本. NFA(Nondeterministic Finite Automaton),不确定有穷自动机,表达式主导,NFA去吃文本,贪婪算法吃下去,如果 ...

  4. 基于DFA敏感词查询的算法简析

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要对敏感词做一个过滤,首先有几个方案可以选择: a.直 ...

  5. java实现敏感词过滤(DFA算法)

    小Alan在最近的开发中遇到了敏感词过滤,便去网上查阅了很多敏感词过滤的资料,在这里也和大家分享一下自己的理解. 敏感词过滤应该是不用给大家过多的解释吧?讲白了就是你在项目中输入某些字(比如输入xxo ...

  6. 使用DFA做文本编辑器的自动提示

    之前看龙书的时候,龙书提到可以在编译器里用动态的生成的NFA自动机来动态匹配自己的输入串,NFA的简单实现其实写起来非常简单,但是我是实际凭感觉写完之后,却觉得并不是非常的好用,在处理自己已经输入过的 ...

  7. DFA 最小化

    NDFA.εNDFA 确定化的细节这里就不总结了,这里说一说DFA最小化的算法. 关于DFA最小化,

  8. C# 词法分析器(五)转换 DFA

    系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 在上一篇文章中,已经得到了与正则表达式等价的 NFA ...

  9. NFA转DFA - json数字识别

    json的主页上,提供了number类型的符号识别过程,如下: 图片引用:http://www.json.org/json-zh.html 实际上这张图片表示的是一个状态机,只是状态没有标出来.因为这 ...

随机推荐

  1. FileProvider记录下

    Mark下FileProvider,阿里巴巴Android开发手册有如下要求:[强制]应用间共享文件时,不要通过放宽文件系统权限的方式去实现,而应使用FileProvider. 知识点记录:1. An ...

  2. Qt ------- QByteArray操作注意

    使用QByteArray方法把数据存入QByteArray需要是char型数据,如果需要存入无符号8位数据,如下: QByteArray data; data[0] = 0xFF; 即使通过data[ ...

  3. 如何写出高性能DOM?

    为什么要写高性能DOM? 一个网站,在页面上承载最多内容的就是DOM,而且无论是我们通过加载JS.加载图片,他们也是通过写HTML标签来实现的.而我们性能优化要做的无非就是几大块: 站点的网络消耗 D ...

  4. vs 统计有效代码行数

    1.Visual Studio中,crtl+Shift+F,输入b*[^:b#/]+.*$ ,查找范围:选择整个解决方案,查找选项:使用正则表达式,文件类型:*.cs;*.cshtml  选择查找全部

  5. Chrome浏览器启动页被360导航篡改解决方法

    右键Chrome浏览器快捷方式,选择“属性”,在“目标”的结尾处有添加的网址,删了即可. 2 如果在结尾处没有任何网址,可以添加“ -nohome”,这样下次启动时,就会打开一个空白页,也就不会打开被 ...

  6. 【洛谷 P4180】【模板】严格次小生成树[BJWC2010](倍增)

    题目链接 题意如题. 这题作为我们KS图论的T4,我直接打了个很暴力的暴力,骗了20分.. 当然,我们KS里的数据范围远不及这题. 这题我debug了整整一个晚上还没debug出来,第二天早上眼前一亮 ...

  7. 简易微信小程序签到功能

    一.效果图 点击签到后 二.数据库 用一张数据表存用户签到的信息,每次用户签到都会往表中添加一条记录了用户id和签到日期的数据,如下图 三.后端 后端写两个接口,一个用于查询用户今日是否签到和签到记录 ...

  8. new操作符的内部运行解析

    在加上new操作符,我们就能完成传统面向对象的class + new的方式创建对象,在Javascript中,我们将这类方式成为Pseudoclassical. 基于上面的例子,我们执行如下代码   ...

  9. 4.0docker部署

    设置容器的端口映射 -P  :容器暴露的所有端口映射 -p :指定映射容器暴露的端口 Nginx部暑流程 docker run -p 80 --name web -t -i ubuntu /bin/b ...

  10. querySelector()与querySelectorAll()

    1.querySelector() 参数:css选择器 返回匹配指定css选择器元素的第一个子元素 2.querySelectorAll() 参数:css选择器 返回匹配指定css选择器的所有元素