Scout YYF I
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8598   Accepted: 2521

Description

YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's base. After overcoming a series difficulties, YYF is now at the start of enemy's famous "mine road". This is a very long road, on which there are numbers of mines. At first, YYF is at step one. For each step after that, YYF will walk one step with a probability of p, or jump two step with a probality of 1-p. Here is the task, given the place of each mine, please calculate the probality that YYF can go through the "mine road" safely.

Input

The input contains many test cases ended with EOF.
Each test case contains two lines.
The First line of each test case is N (1 ≤ N ≤ 10) and p (0.25 ≤ p ≤ 0.75) seperated by a single blank, standing for the number of mines and the probability to walk one step.
The Second line of each test case is N integer standing for the place of N mines. Each integer is in the range of [1, 100000000].

Output

For each test case, output the probabilty in a single line with the precision to 7 digits after the decimal point.

Sample Input

1 0.5
2
2 0.5
2 4

Sample Output

0.5000000
0.2500000

Source

题意:一条路上,有n个炸弹,给出每个炸弹的位置,一次走一步的概率是p,走两步的概率是1-p。求安全走完的概率。

//f[i]到达i点的概率
//f[i]=p*f[i-1]+(1-p)*f[i-2]
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=;
struct matrix{
double s[][];
matrix(){
memset(s,,sizeof s);
}
};
int n,num[N];double p;
matrix operator *(const matrix &a,const matrix &b){
matrix c;
for(int i=;i<;i++){
for(int j=;j<;j++){
for(int k=;k<;k++){
c.s[i][j]+=a.s[i][k]*b.s[k][j];
}
}
}
return c;
}
double fpow(matrix a,int p){
matrix res;
for(int i=;i<;i++) res.s[i][i]=;
for(;p;p>>=,a=a*a) if(p&) res=res*a;
return res.s[][];
}
int main(){
while(~scanf("%d%lf",&n,&p)){
for(int i=;i<=n;i++) scanf("%d",&num[i]);
sort(num+,num+n+);
matrix A;
A.s[][]=p;A.s[][]=1.0;
A.s[][]=1.0-p;A.s[][]=;
double ans=;
for(int i=;i<=n;i++){
ans*=(1.0-fpow(A,num[i]-num[i-]-));
}
printf("%.7f\n",ans);
}
return ;
}

poj3744 Scout YYF I[概率dp+矩阵优化]的更多相关文章

  1. POJ3744 Scout YYF I 概率DP+矩阵快速幂

    http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...

  2. poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)

    F - Scout YYF I Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  3. POJ 3744 Scout YYF I 概率dp+矩阵快速幂

    题目链接: http://poj.org/problem?id=3744 Scout YYF I Time Limit: 1000MSMemory Limit: 65536K 问题描述 YYF is ...

  4. 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 ...

  5. poj 3744 Scout YYF I(概率dp,矩阵优化)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5020   Accepted: 1355 Descr ...

  6. hdu 4576(简单概率dp | 矩阵优化)

    艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle?  感觉很不公平.大家算法都一致,因为我程序没有那 ...

  7. POJ3744 Scout YYF I (矩阵优化的概率DP)

    Scout YYF I YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into th ...

  8. [Poj3744]Scout YYF I (概率dp + 矩阵乘法)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9552   Accepted: 2793 Descr ...

  9. poj4474 Scout YYF I(概率dp+矩阵快速幂)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4100   Accepted: 1051 Descr ...

随机推荐

  1. Struts2- 设置默认拦截器

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...

  2. 什么是服务端渲染、客户端渲染、SPA、预渲染,看完这一篇就够了

    服务端渲染(SSR) 简述:     又称为后端渲染,服务器端在返回html之前,在html特定的区域特定的符号里用数据填充,再给客户端,客户端只负责解析HTML.     鼠标右击点击查看源码时,页 ...

  3. TensorFlow基础笔记(11) conv2D函数

    #链接:http://www.jianshu.com/p/a70c1d931395 import tensorflow as tf import tensorflow.contrib.slim as ...

  4. php将汉字转换为拼音和得到词语首字母(二)

    <?php class Pinyin{ private $_outEncoding = "GB2312"; public function getPinyin($str,$p ...

  5. [Java并发包学习七]解密ThreadLocal

    概述 相信读者在网上也看了非常多关于ThreadLocal的资料,非常多博客都这样说:ThreadLocal为解决多线程程序的并发问题提供了一种新的思路:ThreadLocal的目的是为了解决多线程訪 ...

  6. spark on yarn(zookeeper 配置)

    http://database.51cto.com/art/201404/435630.htm

  7. electron-searchMovies

    之前学了electron,前段时间又学了一下vue,为了增加熟练度决定将两者结合做个有趣的东西.想来想去最后决定将原来用 PyQt 写的MovieHeavens重新写一遍,使用electron-vue ...

  8. 网页中Span和Div的区别

    它们被用来组合一大块的HTML代码并赋予一定的信息,大部分用类属性class和标识属性id与元素联系起来,见CSS中级指南的类和id选择符. span和div的不同之处在于span是内联的,用在一小块 ...

  9. 针对后台列表table拖拽比较实用的jquery拖动排序

    <!DOCTYPE html> <html lang="en"> <head>  <meta charset="UTF-8&qu ...

  10. 使用matlab批量处理图像后在指定文件夹存储

    使用matlab批量处理图像后在指定文件夹存储 clear;clc;close all; Files=dir('D:\文件及下载相关\文档\MATLAB\postgraduate\Kodak\*.jp ...