poj 1625 (AC自动机 + dp + 高精度(java) )
来源:互联网 发布:网络春晚2017在线观看 编辑:程序博客网 时间:2024/05/21 10:23
RE 了n久,没想到最后是因为死在了编码上
import java.util.*;import java.math.*;import java.io.*;public class Main { final static int NODE = 105; final static BigInteger ZERO = BigInteger.ZERO, ONE = BigInteger.ONE; static int code[] = new int[256], chd[][] = new int[NODE][55]; static int val[] = new int[NODE], sz = 1, fail[] = new int[NODE]; public static void insert (String s){ int p = 0; for (int i = 0; i < s.length(); i ++){ int xx = s.charAt(i); int c = code[xx]; if (chd[p][c] == 0){ chd[p][c] = sz ++; } p = chd[p][c]; } val[p] = 1; } public static void getfail (final int CHD){ Queue<Integer> q = new LinkedList<Integer>(); for (int i = 0; i < CHD; i ++){ fail[chd[0][i]] = 0; if (chd[0][i] > 0){ q.add(chd[0][i]); } } while (!q.isEmpty()){ int t = q.remove(); for (int i = 0; i < CHD; i ++){ if (chd[t][i] > 0){ q.add(chd[t][i]); fail[chd[t][i]] = chd[fail[t]][i]; val[chd[t][i]] += val[chd[fail[t]][i]]; }else{ chd[t][i] = chd[fail[t]][i]; } } } } public static void main (String args[])throws Exception{ int n, m, p; Scanner cin = new Scanner(new BufferedInputStream(System.in), "ISO-8859-1"); n = cin.nextInt(); m = cin.nextInt(); p = cin.nextInt(); String ss = cin.nextLine(); ss = cin.nextLine(); for (int i = 0; i < ss.length(); i ++){ int c = ss.charAt(i); code[c] = i; } for (int i = 0; i < p; i ++){ String s = cin.nextLine(); insert (s); } getfail (n); BigInteger dp[][] = new BigInteger[55][105]; for (int i = 0; i < 55; i ++){ for (int j = 0; j < 105; j ++){ dp[i][j] = ZERO; } } int CHD = n; dp[0][0] = ONE; for (int i = 0; i < m; i ++){ for (int j = 0; j < sz; j ++){ if (val[j] == 0){ for (int h = 0; h < CHD; h ++){ int v = chd[j][h]; if (val[v] == 0){ dp[i+1][v] = dp[i+1][v].add(dp[i][j]); } } } } } BigInteger ans = ZERO; for (int i = 0; i < sz; i ++){ ans = ans.add(dp[m][i]); } System.out.println (ans); }}
- poj 1625 (AC自动机 + dp + 高精度(java) )
- poj 1625 Censored! AC自动机+DP +高精度 + C艹 + java
- POJ--1625[Censored!] AC自动机+DP+高精度
- POJ 1625(ac自动机+dp+高精度)
- POJ 1625 ac自动机+高精度dp
- poj 1625 Censored!(AC自动机+DP+高精度)
- poj 1625 Censored! AC自动机+dp+高精度
- [AC自动机+dp+高精度] poj 1625 Censored!
- poj 1625(ac自动机+dp+高精度)
- POJ 1625 Censored! AC自动机+DP+高精度 *
- POJ 1625 Censored! AC自动机 简单DP 高精度
- POJ 1625 Censored! (AC自动机+DP+高精度,5级)
- POJ 1625 Censored! (AC自动机 + 高精度 + DP)
- [POJ 1625] Censored! (AC自动机+DP+高精度)
- 1625 Censored! ac自动机+dp+高精度
- POJ 1625 AC自动机+DP
- POJ 1625 Censored!(自动机DP+高精度)
- poj 1625 Censored!//AC自动机+DP+大数
- 找工作之“二叉搜索树”
- 各模块常用BAPI速查
- EJB到底是什么,真的那么神秘吗??
- Boyer-Moore-Horspool-Sunday 算法
- MySQL命令行导出数据库
- poj 1625 (AC自动机 + dp + 高精度(java) )
- 网络管理服务器多做之过
- 【分享】4月安徽区域微博数据之10W抽取样本
- 插入排序
- 8、从零开始学习JAVA--继承及super的用法
- Boyer–Moore string search algorithm
- mysql profile使用
- SAP二分查找法
- 深入理解Android消息处理系统——Looper、Handler、Thread