转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove

题意:给出一个自动机,给出所有的转移,其中还有一个矩阵,如果(u,c)=0,直接转移,字符c被接收,否则也会转移但是字符c不会被转移,也就是下一个字符依旧是字符c。

http://acm.sgu.ru/problem.php?contest=0&problem=201

题意理解了很久。。。。。

自动机都给出了状态和转移,显然是个DP。。。

但是由于存在(u,c)=1的情况,即字符不变,所以需要预处理一下,得到最终接受字符的状态

记忆化搜索即可,可能出现死循环的情况,判定为不可转移

需要高精度

import java.util.*;
import java.io.*;
import java.math.*;
public class Solution {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(in, out);
out.close();
}
}
class Task{
static int go[][]=new int [1005][26];
static boolean end[]=new boolean [1005];
static int x[][]=new int [1005][26];
static int to[][]=new int [1005][26];
int dfs(int now,int ch){
if(x[now][ch]==0){
return to[now][ch]=go[now][ch];
}
if(to[now][ch]!=-1)
return to[now][ch];
to[now][ch]=0;
return to[now][ch]=dfs(go[now][ch],ch);
}
void solve(InputReader in,PrintWriter out){
String S=in.next();
int m=S.length();
int n=in.nextInt();
int s=in.nextInt();
int endcnt=in.nextInt();
for(int i=1;i<=n;i++)
end[i]=false;
for(int i=0;i<endcnt;i++){
int u=in.nextInt();
end[u]=true;
}
for(int i=1;i<=n;i++){
for(int j=0;j<m;j++)
go[i][j]=in.nextInt();
}
for(int i=1;i<=n;i++){
for(int j=0;j<m;j++){
x[i][j]=in.nextInt();
to[i][j]=-1;
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<m;j++){
dfs(i,j);
}
}
int l=in.nextInt();
BigInteger dp[][]=new BigInteger [65][1005];
for(int i=0;i<=l;i++)
for(int j=1;j<=n;j++)
dp[i][j]=BigInteger.ZERO;
dp[0][s]=BigInteger.ONE;
for(int i=1;i<=l;i++){
for(int j=1;j<=n;j++){
for(int k=0;k<m;k++){
if(to[j][k]>0)
dp[i][to[j][k]]=dp[i][to[j][k]].add(dp[i-1][j]);
}
}
}
BigInteger ans=BigInteger.ZERO;
for(int i=1;i<=n;i++)
if(end[i])
ans=ans.add(dp[l][i]);
out.println(ans);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer; public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
} public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}

SGU 201 Non Absorbing DFA (DP)的更多相关文章

  1. 201. Non Absorbing DFA

    题意好难看懂的说... 有限状态自动机DFA是这么一个有序组<Σ, U, s, T, phi>:Σ代表输入字符集,表示此自动机的工作范围:U代表所有的状态集合:s是初始状态:T是最终状态: ...

  2. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  3. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  4. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  5. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  6. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  7. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  8. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  9. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

随机推荐

  1. python Memo

    list&tuple 运算 乘以constant >>> x = ((1,2),) >>> x*2 ((1, 2), (1, 2)) >>> ...

  2. Python的编码规范(PEP 8 & Google Python guide)

    PEP 8 Python 代码规范整理 click here Goole Python 风格指南 中文版 click here 大家有取舍的看吧. 因为文章不是原创的,所以只贴地址,给大家造成麻烦了, ...

  3. Java 拾遗

    1.选择表达式中的类型转换 public class Test { public void static main(String args[]){ int i = 5; System.out.prin ...

  4. 【Windows 8 Store App】学习三:HTTP

    原文 http://www.cnblogs.com/java-koma/archive/2013/05/22/3093309.html 1,HttpClient Win 8提供了System.Net. ...

  5. 灵活运用Zend框架

    $aAwardMem = $this->dao_raward->getAwardAndMem($where,'award_level asc',false,false,false,'awa ...

  6. WISPr1.0

    王桢珍 王兵 侯志强 苑红 中国移动研究院 网络技术研究所, 北京100053 摘要   本文详细介绍了WLAN国际漫游的WISPr1.0技术规范并探讨其具体实现,包括基于WISPr1.0的WLAN国 ...

  7. 填充Z形二维数组

    形如  1   3 4 10  2  5 9 11  6  8 12 15  7 13 14 16 的数组称谓Z形二维数组.填充这样的数组其实只要按照Z形进行行走填充即可,设置一个flag指示方向,行 ...

  8. 解决URL请求中的中文乱码问题

    解决URL提交中文出现乱码有两种办法:1.请求端的中字符有encodeURI进行一次转码,如: var url="/getUser?name="+encodeURI(name);服 ...

  9. 【ActionBar的使用】

    在AS工程中使用ActionBar 简单实用: 1.功能清单文件中指定主题标签属性Theme.Holo或其子类 <application android :theme="@androi ...

  10. Java日期计算之Joda-Time

    http://rensanning.iteye.com/blog/1546652 Joda-Time提供了一组Java类包用于处理包括ISO8601标准在内的date和time.可以利用它把JDK D ...