转载请注明出处,谢谢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. cad移动图案

    1.键盘按快捷键M,鼠标变成小方块,选中图案,右击,左击拖动图像 2.选中图像,键盘按m,拖动图像 3.选中图像,右击,图像移动

  2. 7.使用ProcessBuilder执行本地命令(转)

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.IO ...

  3. 2014第16周三CSS布局再学习摘录

    今天尝试写了下前端页面,费了不少时间,做出的结果仍然惨不忍睹,感觉很简单的几个页面,在现有框架多个样式混杂下就是感觉很不自在随意,晚上回来又看了些div+css方面的基础知识. 1.CSS的class ...

  4. 2016 Multi-University Training Contest 2 总结

    第二次多校,出师未捷身先死 欣君看了一下09题,高呼水题,迅速码好,一A. 我看了11题,发现分奇偶讨论即可,于是按思路写好,一A. 欣君搞鼓出01题的一个公式,于是我照着写,一WA.简直不可思议,发 ...

  5. /dev/null &

    java -cp .:ojdbc14.jar com.eucalyptus.dataguard.DBCheck dadifilm slbcheck Aa7788123 > /dev/null & ...

  6. 【转】python import的用法

    [转自http://blog.sina.com.cn/s/blog_4b5039210100ennq.html] 在python用import或者from...import来导入相应的模块.模块其实就 ...

  7. 程序猿的量化交易之路(20)--Cointrader之Assert实体(8)

    转载需说明出处:http://blog.csdn.net/minimicall, http://cloudtrade.top 不论什么可交易的都能够称之为Assert,资产.其类代码例如以下: pac ...

  8. 通过SecureCRT下载远程Linux服务器上的文件到本地Windows

    sz  文件名[先cd到需要下载的文件的目录层] [root@is13084905-0233 bookinterface]# sz test.txt rz Starting zmodem transf ...

  9. ##DAY14——StoryBoard

    •iOS下可视化编程分为两种⽅式:xib和storyboard. •在使用xib和storyboard创建GUI过程中,以XML文件格式 存储在Xcode中,编译时生成nib的二进制文件.在运行时, ...

  10. Scala io操作

    1. 读文件 scala特有的是scala.io.Source,例如: import scala.io._ Source.fromFile(“cn.scala”,”utf8”).mkString 逐行 ...