Beispiel #1
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;
}
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;
}