POJ3744 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
//using namespace std;
const int maxn=;
const double eps=1e-;
const int modn=;
int n;double p,ans;
int b[]={};
double c[]={};
struct mat{
double e[][];
mat(){memset(e,,sizeof(e));}
};mat a;
void yu(){
memset(b,,sizeof(b));
a.e[][]=1.0;
a.e[][]=1.0-p;
a.e[][]=p;
ans=;
}
mat Mul(mat x,mat y){
mat z;
for(int i=;i<=;i++){
for(int j=;j<=;j++){
for(int k=;k<=;k++){
z.e[i][j]+=x.e[i][k]*y.e[k][j];
}
}
}
return z;
}
mat Pow(mat x,int k){
mat z;
z.e[][]=;z.e[][]=;
while(k){
if(k&){
z=Mul(x,z);
}
k/=;
x=Mul(x,x);
}
return z;
}
int main(){
while(~scanf("%d%lf",&n,&p)){
yu();
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
}
std::sort(b+,b++n);
b[]=;
int f=;
for(int i=;i<=n;i++){
if(b[i]==b[i-]+){
printf("%.7f\n",0.0);
f=;
break;
}
}if(f) continue;
c[]=1.0,c[]=p;
for(int i=;i<=n;i++){
if(b[i]-b[i-]==);
else if(b[i]-b[i-]==){
ans*=p;
}else{
mat z=Pow(a,b[i]-b[i-]-);
ans*=c[]*z.e[][]+c[]*z.e[][];
}
ans*=(1.0-p);
}
printf("%.7f\n",ans+eps);
}
return ;
}
POJ3744 Scout YYF I 概率DP+矩阵快速幂的更多相关文章
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
题目链接: http://poj.org/problem?id=3744 Scout YYF I Time Limit: 1000MSMemory Limit: 65536K 问题描述 YYF is ...
- poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)
F - Scout YYF I Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj3744 Scout YYF I[概率dp+矩阵优化]
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8598 Accepted: 2521 Descr ...
- poj4474 Scout YYF I(概率dp+矩阵快速幂)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4100 Accepted: 1051 Descr ...
- Scout YYF I POJ - 3744(概率dp + 矩阵快速幂)
题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * d ...
- poj3744 (概率DP+矩阵快速幂)
http://poj.org/problem?id=3744 题意:在一条铺满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,10000000 ...
- POJ-3744 Scout YYF I 概率DP
题目链接:http://poj.org/problem?id=3744 简单的概率DP,分段处理,遇到mine特殊处理.f[i]=f[i-1]*p+f[i-2]*(1-p),i!=w+1,w为mine ...
- POJ 3744 Scout YYF I (概率dp+矩阵快速幂)
题意: 一条路上,给出n地雷的位置,人起始位置在1,向前走一步的概率p,走两步的概率1-p,踩到地雷就死了,求安全通过这条路的概率. 分析: 如果不考虑地雷的情况,dp[i],表示到达i位置的概率,d ...
- poj 3744 概率dp+矩阵快速幂
题意:在一条布满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,100000000]. 每次前进p的概率前进一步,1-p的概率前进1-p步.问 ...
随机推荐
- python模块之imghdr检测图片类型
1. imghdr是什么 imghdr是一个用来检测图片类型的模块,传递给它的可以是一个文件对象,也可以是一个字节流. 能够支持的图片格式: 2. 如何使用 提供了一个api叫做imghdr.what ...
- 大聊PYthon----生成器
再说迭代器与生成器之前,先说一说列表生成式 列表生成式 什么是列表生成式呢? 这个非常简单! 先看看普通青年版的! >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, ...
- koa源码阅读[1]-koa与koa-compose
接上次挖的坑,对koa2.x相关的源码进行分析 第一篇.不得不说,koa是一个很轻量.很优雅的http框架,尤其是在2.x以后移除了co的引入,使其代码变得更为清晰. express和koa同为一批人 ...
- css3旋转、过渡、动画属性
1.transform 该属性对元素进行旋转.缩放.移动和倾斜 translate元素从当前位置移动 rotate元素顺时针旋转 scale元素的尺寸增大或减小 skew元素翻转 2.transiti ...
- php sprintf格式化注入
URL:http://efa4e2c2b8df4ce69454639f4e3727071652c31167f341a4.game.ichunqiu.com/ 简单的说就是sprintf中%1$\'会将 ...
- WebClient vs HttpClient vs HttpWebRequest
转载:http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/ Just when I was startin ...
- CentOS系统yum源配置修改、yum安装软件包源码包出错解决办法apt.sw.be couldn't connect to host
yum安装包时报错: Could not retrieve mirrorlist http://mirrorlist.repoforge.org/el6/mirrors-rpmforge error ...
- [Ext JS 4]后台自动产生图档
前言 [Ext JS 4] 实战之将chart导出为png, jpg 格式的文件 承接上一篇, 我们可以做到在Browser端打开一个Chart,并导出为png或是jpg 等格式的图档. 但实际的需求 ...
- ActiveMQ objecmessage 无法调用问题。
http://activemq.apache.org/objectmessage.html
- SGU 208. Toral Tickets
208. Toral Tickets time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ou ...