Beispiel #1
0
int main() {
  short nCase;
  scanf("%hd", &nCase);
  for(short iCase = 1; iCase<=nCase; iCase++) {
    short t0;
    ac.clear();
    scanf("%hd", &t0);
    while(t0--) {
      char _[21];
      scanf("%*c%s", _);
      size_t __ = strlen(_);
      for(char *i = _; i!=_+__; i++)
        *i = c2i(*i);
      ac.insertPattern(_, _+__);
    }
    ac.construct();
    scanf("%hd", &t0);
    memset(prob, 0, sizeof(prob));
    while(t0--) {
      char t1;
      scanf("%*c%c", &t1);
      scanf("%lf", prob+c2i(t1));
    }
    scanf("%hd", &t0);
    memset(f, 0, sizeof(f));
    f[0][0] = 1;
    for(int i = 0; i<t0; i++)
      for(short j = 0; j<ac.size(); j++)
        if(f[i][j])
          for(short k = 0; k < 62; k++)
            if(prob[k] && !ac.output(ac.go(j, k)).size())
              f[i+1][ac.go(j, k)] += f[i][j]*prob[k];
    double res = 0;
    for(short j = 0; j<ac.size(); j++)
      res += f[t0][j];
    printf("Case #%hd: %lf\n", iCase, res);
  }
  return 0;
}
Beispiel #2
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;
}