[JSOI2009] 有趣的游戏
1444: [Jsoi2009]有趣的游戏
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 1800 Solved: 645
[Submit][Status][Discuss]
Description

Input

注意 是0<=P, n , l, m≤ 10.
Output

Sample Input
3 2 2
1 2
1 2
AB
BA
AA
input 2
3 4 2
1 2
1 2
AABA
ABAA
BAAA
Sample Output
0.25
0.50
0.25
output 2
0.31
0.33
0.37
HINT

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define D double
const 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]);
puts("");
}
*/
} 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] 有趣的游戏的更多相关文章
- BZOJ:4820: [Sdoi2017]硬币游戏&&BZOJ:1444: [Jsoi2009]有趣的游戏(高斯消元求概率)
1444: [Jsoi2009]有趣的游戏 4820: [Sdoi2017]硬币游戏 这两道题都是关于不断随机生成字符后求出现给定字符串的概率的问题. 第一题数据范围较小,将串建成AC自动机以后,以A ...
- BZOJ 1444: [Jsoi2009]有趣的游戏 [AC自动机 高斯消元]
1444: [Jsoi2009]有趣的游戏 题意:每种字母出现概率\(p_i\),有一些长度len的字符串,求他们出现的概率 套路DP的话,\(f[i][j]\) i个字符走到节点j的概率,建出转移矩 ...
- BZOJ 1444:[JSOI2009]有趣的游戏
BZOJ 1444:[JSOI2009]有趣的游戏 题目链接 首先我们建出Trie图,然后高斯消元. 我们设\(f_i\)表示经过第\(i\)个点的期望次数: \[ f_x=\sum i\cdot p ...
- BZOJ 1444 [Jsoi2009]有趣的游戏 (AC自动机 + 概率DP + Gauss)
1444: [Jsoi2009]有趣的游戏 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1382 Solved: 498[Submit][Statu ...
- 【BZOJ1444】[JSOI2009]有趣的游戏(高斯消元,AC自动机)
[BZOJ1444][JSOI2009]有趣的游戏(高斯消元,AC自动机) 题面 BZOJ 题解 先把\(AC\)自动机构建出来,最好构成\(Trie\)图.然后这样子显然是在一个有向图中有一堆概率的 ...
- 1444: [Jsoi2009]有趣的游戏
1444: [Jsoi2009]有趣的游戏 链接 分析: 如果一个点回到0号点,那么会使0号点的概率增加,而0号点的概率本来是1,不能增加,所以这题用期望做. 设$x_i$表示经过i的期望次数,然后初 ...
- 【bzoj1444】[Jsoi2009]有趣的游戏
1444: [Jsoi2009]有趣的游戏 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1007 Solved: 334[Submit][Statu ...
- 【BZOJ1444】[Jsoi2009]有趣的游戏 AC自动机+概率DP+矩阵乘法
[BZOJ1444][Jsoi2009]有趣的游戏 Description Input 注意 是0<=P Output Sample Input Sample Output HINT 30%的 ...
- luogu P6125 [JSOI2009]有趣的游戏
LINK:有趣的游戏 直接说做法了.首先是 我是不会告诉你我看完题后不太会 摸了2h鱼后看题解 一直翻发现自己题目有些没读完整.. 题目中说了每个字符串长度相同 而我一直在思考AC自动机可能存在一些节 ...
随机推荐
- Learn the shell
learn the shell what is the shell? when we speak of the command line,we are really to the shell.Actu ...
- linux服务进程管理
1.查看linux占用内存/CPU最多的进程 查使用内存最多的10个进程 ps -aux | sort -k4nr | head -n 10 或者top (然后按下M,注意大写) 查使用CPU最多的1 ...
- Codeforces Round #352 (Div. 2) C
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- vue刨坑(二)
vue实例 vue实例 每一个应用都是通过vue这个构造函数创建根实例(root instance),启动 new vue(选项对象) 需要传入选项对象,对象包含挂载元素,数据,模板,方法等. el: ...
- 获得touch事件,jquery绑定事件监听器,ios设备上打开touch状态以响应focus,active等伪类
2. 默认的监听方式 document.addEventListener('touchstart', function(){ alert('hello'); }, false); 使用jquery时 ...
- centos 下文件夹共享
[root@localhost share]# yum install samba -y[root@localhost share]# cp /etc/samba/smb.conf /etc/samb ...
- Linux 设备驱动--- 阻塞型字符设备驱动 --- O_NONBLOCK --- 非阻塞标志【转】
转自:http://blog.csdn.net/yikai2009/article/details/8653697 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 阻塞 阻 ...
- UVALIVE 2955 Vivian's Problem
参考: http://blog.csdn.net/acm_cxlove/article/details/7860735 感觉这里需要记录一下 #include <map> #include ...
- 小知识:SPI四种模式区别【转】
转自:http://home.eeworld.com.cn/my/space-uid-80086-blogid-119198.html spi四种模式SPI的相位(CPHA)和极性(CPOL)分别可以 ...
- Nginx 兼容IE8
前言 前段时间由于业务需要,在服务器上新增一个服务专门接收各个门店的业务结算数据,接口文档指明需要使用https协议.这本不是什么问题,因为之前服务器已经有配置过https.但等到服务部署之后才发现这 ...