BZOJ 1444: [Jsoi2009]有趣的游戏
生活随笔
收集整理的這篇文章主要介紹了
BZOJ 1444: [Jsoi2009]有趣的游戏
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1444: [Jsoi2009]有趣的游戲
Time Limit:?10 Sec??Memory Limit:?64 MBSubmit:?1114??Solved:?386
[Submit][Status][Discuss]
Description
Input
注意 是0<=P
Output
Sample Input
Sample Output
HINT
?
?
30%的數(shù)據(jù)保證, n ≤ 2. 50%的數(shù)據(jù)保證, n ≤ 5. 100%的數(shù)據(jù)保證, n , l, m≤ 10.
?
Source
[Submit][Status][Discuss]?
先做AC自動機(jī),然后本來想gauss,但是聽說做50次自乘就行,那豈不是賊簡單。
?
1 #include<cstdio> 2 #include<cstring> 3 #define siz 125 4 char s[15]; double d[15],f[siz][siz],p[siz][siz]; 5 int n,m,l,q[siz],hd,tl,fl[siz],ch[siz][15],ed[siz],bp[15],tot=1; 6 main(){ 7 scanf("%d%d%d",&n,&l,&m); 8 for(int j=0,x,y;j<m;++j) 9 scanf("%d%d",&x,&y),d[j]=1.0*x/y; 10 for(int j=1,t;j<=n;++j){ 11 scanf("%s",s);t=1; 12 for(int i=0;i<l;++i){ 13 if(!ch[t][s[i]-'A']) 14 ch[t][s[i]-'A']=++tot; 15 t=ch[t][s[i]-'A']; 16 } 17 ed[t]=j,bp[j]=t; 18 } 19 for(int j=0;j<m;++j) 20 if(!ch[1][j])ch[1][j]=1; 21 else fl[q[tl++]=ch[1][j]]=1; 22 while(hd!=tl){ 23 int t=q[hd++]; 24 for(int j=0;j<m;++j) 25 if(!ch[t][j])ch[t][j]=ch[fl[t]][j]; 26 else fl[q[tl++]=ch[t][j]]=ch[fl[t]][j]; 27 } 28 for(int i=1;i<=tot;++i) 29 if(!ed[i])for(int j=0;j<m;++j) 30 f[i][ch[i][j]]+=d[j]; 31 else f[i][i]=1; 32 for(int t=1;t<=50;++t){ 33 memset(p,0,sizeof(p)); 34 for(int k=1;k<=tot;++k) 35 for(int i=1;i<=tot;++i) 36 for(int j=1;j<=tot;++j) 37 p[i][j]+=f[i][k]*f[k][j]; 38 memcpy(f,p,sizeof(f)); 39 } 40 for(int i=1;i<=n;++i)printf("%.2lf\n",f[1][bp[i]]); 41 } 42?
@Author: YouSiki
轉(zhuǎn)載于:https://www.cnblogs.com/yousiki/p/6476418.html
總結(jié)
以上是生活随笔為你收集整理的BZOJ 1444: [Jsoi2009]有趣的游戏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [洛谷2月月月赛]富金森林公园
- 下一篇: pat 团体赛练习题集 L2-008.