ASC(2)A(大数+图论DP)
来源:互联网 发布:淘宝客如何用网站推广 编辑:程序博客网 时间:2024/04/30 05:00
Non Absorbing DFA
Problem Description
In the theory of compilers and languages finite state machines, also known as finite automata are widely used. Deterministic finite automation (DFA) is an ordered set <Σ, U, s, T, φ>where Σ is the finite set called input alphabet, U is the finite set of states, s ∈U is the initial state, T ⊂ U is the set of terminal states and φ : U × Σ → U is the transition function.
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 φ(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.
In some cases to simplify the automation the concept of nonabsorbing edges is introduced. That is, in addition to φ the function Х : U × Σ → {0, 1} is introduced and 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.
It is said that such automation accepts some string α if after a number of steps it transits to the terminal state and the input string becomes empty.
Your task is given the DFA with nonabsorbing edges to compute the number of strings of the given length N that it accepts.
Input
The first line of the input file contains Σ - a subset of the English alphabet, several different small letters. Next line contains K = |U| - the number of states of the automation (1 ≤ K ≤ 1000). Let states be numbered from 1 to K. Next line contains S (1 ≤ S ≤ K) - the initial state, followed by L = |T| - the number of terminal states and then L different integer numbers ranging from 1 to K - the numbers of terminal states.
Next K lines contain |Σ| integer numbers each and define φ. Next K lines define Х in a similar way. The last line of the input file contains N(1 ≤ N ≤ 60).
Output
Sample Input
ab21 1 22 11 20 10 03
Sample Output
2
Hint
- ASC(2)A(大数+图论DP)
- ASC(22)H(大数+推公式)
- ASC(1)C(树形DP)
- uva10069(DP+大数)
- ACdream 1216 (ASC训练1) Beautiful People(DP)
- ASC(1)E(矩阵快速幂+简单DP)
- ASC(21)A(二分图最大匹配)
- 大数A*B(大数乘) 浙江工业大学
- HDU5568 sequence2(dp+大数)
- hdu5568 sequence2(dp+大数)
- 小数A+B(大数)
- A/B Problem(大数)
- 归并排序(ASC)
- 堆排序(ASC)
- asc
- 【DP】 (ASC 44) Braess's Paradox
- poj3181 (dp种类数+大数加法)
- sgu - 269 - Rooks(大数dp)
- [Windows Enterprise Library]-微软企业库入门
- PKM(professional knowledge manage)专业知识管理
- 最简单的基于FFmpeg的封装格式处理:视音频分离器简化版(demuxer-simple)
- Hashing Table(笔记)
- css 清除浮动
- ASC(2)A(大数+图论DP)
- 我的程序员之路2
- LeetCode刷题笔录Palindrome Partitioning
- exception类的实现
- ASCII Table and Description
- STM32驱动W25X64存储器
- isdigit()在<ctype.h>中
- mybatis代码生成的几种方式
- Country Code