[JSOI2009] Fun Games

Source: Internet
Author: User

1444: [Jsoi2009] Funny game time limit:10 Sec Memory limit:64 MB
submit:1800 solved:645
[Submit] [Status] [Discuss] Description

Input

Note that it is 0<=p, N, L, m≤10.

Output

Sample InputInput 1
3 2 2
0 S
0 S
Ab
BA
Aa
Input 2
3 4 2
0 S
0 S
Aaba
Abaa
BAAASample OutputOutput 1
0.25
0.50
0.25

Output 2
0.31
0.33
0.37
HINT

after building an AC automaton, direct the transfer matrix and then direct the Gaussian elimination element. (since it is a routine problem I will not say much 2333)
#include <bits/stdc++.h> #define LL long longusing namespace std; #define D doubleconst int maxn=205;const d eps=1e-9; int Ch[maxn][27],n,m,l,cnt,x,y;int f[maxn],rot=0,dy[27];D a[maxn][maxn],p[27];char s[37];bool islef[maxn];inline int Id (char x) {return x ' A ' +1;} inline void Ins (int x) {int now=rot;for (int i=1,c;i<=l;i++) {c=id (s[i]), if (!ch[now][c]) Ch[now][c]=++cnt;now=ch[now    ][C]; }dy[x]=now,islef[now]=1;} inline void Getfail () {queue<int> q;for (int i=1;i<=m;i++) if (Ch[rot][i]) {F[ch[rot][i]]=0,q.push (Ch[rot][i]) ;} int X,v;while (!q.empty ()) {X=q.front (), Q.pop (); for (int i=1;i<=m;i++) {v=ch[x][i];if (!v) {ch[x][i]=ch[f[x]][i]; Continue;} Q.push (v); f[v]=ch[f[x]][i];}}} inline void Build () {a[0][cnt+1]=1;for (int i=0;i<=cnt;i++) {a[i][i]=1;if (!islef[i]) for (int j=1;j<=m;j++) a[ch[i ][J]][I]-=P[J];} /*for (int i=0;i<=cnt;i++) {for (int j=0;j<=cnt+1;j++) printf ("%.2lf", A[i][j]);p UTS ("");} */}inline void xy () {for (int i=0;i<=cnt;i++) {int tmp=i;for (int j=i+1;j<=cnt;j++) if (A[j][i]>a[tmp][i]) tmp=j;if (tmp>i) for (int. k=cnt+1;k>=i;k--) swap (a[i][k],a[tmp][k]); for (int j=i+1;j<= cnt;j++) if (Fabs (A[j][i]) >eps) {D o=a[j][i]/a[i][i];for (int k=cnt+1;k>=i;k--) A[j][k]-=a[i][k]*o;}} for (int i=cnt;i;i--) {for (int j=i+1;j<=cnt;j++) a[i][cnt+1]-=a[i][j]*a[j][cnt+1];a[i][cnt+1]/=a[i][i];}} inline void Solve () {getfail (); build (); XY ();} int main () {scanf ("%d%d%d", &n,&l,&m), for (int i=1;i<=m;i++) scanf ("%d%d", &x,&y), p[i]=x/(d) Y; for (int i=1;i<=n;i++) {scanf ("%s", s+1); Ins (i);} Solve (); for (int i=1;i<=n;i++) printf ("%.2lf\n", a[dy[i]][cnt+1]); return 0;}

  

[JSOI2009] Fun Games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.