int main () {
    int t, ca = 1, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        AC ac;
        for(int i = 0; i < n; ++i) {
            scanf("%s", a);
            ac.insert(a, 1);
        }
        ac.getFail();
        scanf("%d", &n);
        memset(pro, 0, sizeof(pro));
        for(int i = 0; i < n; ++i) {
            char c;
            double p;
            scanf("\n%c%lf", &c, &p);
            pro[ ac.idx(c) ] = p;
        }
        int l;
        scanf("%d", &l);
        for(int i = 0; i < maxnode; ++i) {
            for(int j = 0; j < 110; ++j) dp[i][j] = -1;
        }
        printf("Case #%d: %.6lf\n", ca++, solve(0, l, ac));
    }
    return 0;
}
Пример #2
0
int solve(){
  memset(matchLineCnt, 0, sizeof(matchLineCnt));
  ac.reset();
  for (int i = 0; i < X; i++) ac.insert(patternMat[i], i, Y);
  ac.getFail();
  for (int i = 0; i < N; i++){
    int u = 0;
    for (int j = 0; j < M; j++){
      int c = ac.idx(textMat[i][j]);
      u = ac.ch[u][c];
      for (size_t k = 0; k < ac.val[u].size(); k++){
        int ln = ac.val[u][k];
        if (i - ln >= 0 && j + 1 - Y >= 0){
          matchLineCnt[i - ln][j + 1 - Y]++;
        }
      }
    }
  }
  int total = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      if (matchLineCnt[i][j] == X) total++;
    }
  }
  return total;
}
Пример #3
0
int main()
{
    int TC, n_case(0);
    scanf("%d", &TC);
    while(TC--)
    {
        scanf("%d", &SIGMA_SIZE);
        ac.init();
        scanf("%s", str);
        ac.insert(str);
        ac.construct();
        mat.r = ac.size;
        mat.c = ac.size+1;
        mat.reset();
        memset(vis, 0, sizeof(vis));
        dfs(0);
		mat.gaussInt();
		if(n_case)
			cout << "\n";
		cout << "Case " << ++n_case << ":\n";
		cout << mat.arr[0][ac.size] << "\n";
    }
    return 0;
}