Scout YYF I(POJ 3744)
|
Scout YYF I
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 Sample Output 0.5000000 Source 此题为概率dp
1.求概率:
有N个地雷,分段处理,求每段踩中地雷的概率P,则未踩中的概率为1 - P,再分别相乘。
每段踩中地雷的概率递推式为:dn = p * dn-1 + (1 - p) * dn - 2;
2.对递推式的处理:
由于数据太大,直接递推求解容易tle,所以将递推式转化为矩阵形式(方法http://www.cnblogs.com/sunus/p/4404273.html),再用矩阵快速幂处理。
注意:最终得[dn; dn-1] = [p, 1-p; 1, 0]^(n - 1) * [d1; d0];
d1 = p;
d0 = 1;
因此,[dn; dn-1] = [p, 1-p; 1, 0]^(n - 1) * [p; 1];
因此,dn = ([p, 1-p; 1, 0]^n)[0][0];
#include <cstdio> |
Scout YYF I(POJ 3744)的更多相关文章
- [Poj3744]Scout YYF I (概率dp + 矩阵乘法)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9552 Accepted: 2793 Descr ...
- poj4474 Scout YYF I(概率dp+矩阵快速幂)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4100 Accepted: 1051 Descr ...
- 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)
Charm Bracelet POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...
- 广大暑假训练1(poj 2488) A Knight's Journey 解题报告
题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A (A - Children of the Candy Corn) ht ...
- Games:取石子游戏(POJ 1067)
取石子游戏 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37662 Accepted: 12594 Descripti ...
- BFS 或 同余模定理(poj 1426)
题目:Find The Multiple 题意:求给出的数的倍数,该倍数是只由 1与 0构成的10进制数. 思路:nonzero multiple 非零倍数 啊. 英语弱到爆炸,理解不了题意... ...
- 并查集+关系的传递(poj 1182)
题目:食物链 题意:给定一些关系.判断关系的正确性,后给出的关系服从之前的关系: 思路:难点不在并查集,在于关系的判断,尤其是子节点与根节点的关系的判断: 这个关系看似没给出,但是给出子节点与父节点的 ...
- 昂贵的聘礼(poj 1062)
Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...
- Collecting Bugs(POJ 2096)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 3064 Accepted: 1505 ...
随机推荐
- postgreSql基础命令及linux下postgreSql命令
(1)用户实用程序: createdb 创建一个新的PostgreSQL的数据库(和SQL语句:CREATE DATABASE 相同) createuser 创建一个新的PostgreSQL的用户(和 ...
- hdu 5150 Sum Sum Sum 水
Sum Sum Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- yii 常用路径
yii::app()->homeurl //主页的网址 yii系统变量. //得到proteced目录的物理路径 Yii::app()->basePath; 调用YII框架中jquery: ...
- Linux Shell Bash 带有特殊含义的退出码
linux在执行完一条命令后,使用 echo $? 会显示上一条命令是否执行成功,相关状态码如下 0为成功 表格 D-1. "保留的"退出码 退出码的值 含义 例子 注释 1 通用 ...
- YII的关联查询
先看数据表中的关系是怎样的: customer表中的关系如下: order中的表为: 先在customer中获得order的数据,并与之关联,在 helloController.php 中,代码如下 ...
- iOS - AudioServicesPlay 短频音效播放
前言 extern void AudioServicesPlayAlertSound(SystemSoundID inSystemSoundID) __OSX_AVAILABLE_STARTING(_ ...
- bootstrap学习笔记<三>(文本,代码域,列表)
文本对齐 .text-left:左对齐 .text-center:居中对齐 .text-right:右对齐 .text-justify:两端对齐 <p class="text-left ...
- 利用ajax.dll类库文件实现无刷新
使用这种方法前需要配置相应的环境 1.引用ajax.dll文件 2.在web.config添加如下: <httpHandlers> <add path="ajax/*. ...
- 把excel中的数据导入到数据库
import.php <?php header("Content-Type:text/html;charset=utf-8"); echo '<html> < ...
- linux内核的熵池
也可以看百度科 Linux内核采用熵来描述数据的随机性.熵(entropy)是描述系统混乱无序程度的物理量,一个系统的熵越大则说明该系统的有序性越差,即不确定性越大.在信息学中,熵被用来表征一个符号或 ...