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 ...
随机推荐
- MySQL记录操作
说明:value的值可以为数据,DEFAULT,NULL,expr 含有ATUO_INCREMENT的列可以插入DEFAULT.NULL,或者不插入记录来实现自动增长. 插入记录的三种方法:①可以同时 ...
- js文件的装载和执行
1.浏览器对script引用的js文件分两步,下载,下载完毕后马上执行:这两步都会阻塞浏览器继续解析. 2.加入defer属性,<script defer type="text/jav ...
- 关于PHP HTML <input type="file" name="img"/>上传图片,图片大小,宽高,后缀名。
在我们的系统中,不免要上传图片,视频等文件,在上传中,需要做的一些判断,文件大小等方面. 注意: 在php.ini 中的post_max_size,upload_max_filesize默认为2M,在 ...
- SG函数题目
HDU Fibonacci again and again 思路: 把整个游戏看成三个子游戏,然后求游戏的和 关键理解g(x) = mex(g(y), y€f(x)) , f(x)表示由x点可达的点, ...
- SQL笔记(1)索引/触发器
--创建聚集索引 create clustered index ix_tbl_test_DocDate on tbl_test(DocDate) GO --创建非聚集索引 create nonclus ...
- 强行替换exe图标的方法
说句实话,要想用普通的方法来替换图标,不是完全不可行,当然也不是完全可行.这个看似简单的问题并不是想象中那么容易解决,为什么有人修改exe的图标总是失败,其实他忽视了exe和图标的复杂性,用简单的方法 ...
- Java编程思想学习笔记_5(IO流)
一.用DataInputStream读取字符 可以使用available方法查看还有多少可供存取的字符.示例如下: public class Test1 { public static void ma ...
- fragment入门
[1]在activity布局中定义fragment <?xml version="1.0" encoding="utf-8"?> <Linea ...
- Make 教程
Make 命令教程 原文作者: 阮一峰 原文链接:http://www.ruanyifeng.com/blog/2015/02/make.html (在原文基础上稍作修改) 代码变成可执行文件,叫做编 ...
- Activity中与ListActivity中使用listview区别
Activity中与ListActivity中使用listview区别 一.Activity中与ListActivity中使用listview区别(本身没多大区别,只是ListActivity在lis ...