poj3744 Scout YYF I[概率dp+矩阵优化]
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8598 | Accepted: 2521 |
Description
Input
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
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+矩阵优化]的更多相关文章
- POJ3744 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...
- poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)
F - Scout YYF I Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 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,矩阵优化)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5020 Accepted: 1355 Descr ...
- hdu 4576(简单概率dp | 矩阵优化)
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle? 感觉很不公平.大家算法都一致,因为我程序没有那 ...
- 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 ...
- [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 ...
随机推荐
- jar/war/ear文件的区别
jar/war/ear三种文件,在文件结构上,三者并没有什么不同,它们都采用zip或jar档案文件压缩格式.但是它们的使用目的有所区别: Jar文件(扩展名为. Jar)包含Java类的普通库.资源 ...
- Android.mk文件c++头文件包含问题
Eclipse 中 Android.mk文件c++头文件包含问题 jni中的目录结构如下: 编译找不到头文件 LOCAL_PATH := $(call my-dir)LOCAL_C_INCLUDES ...
- 用 #include “filename.h” 格式来引用非标准库的头文件
用 #include “filename.h” 格式来引用非标准库的头文件(编译器将 从用户的工作目录开始搜索) #include <iostream> /* run this progr ...
- REFLECTOR和FILEDISASSEMBLER的下载与使用
.NET Reflector 下载地址 http://www.aisto.com/roeder/dotnet FileDisassembler 下载地址 http://www.denisbauer.c ...
- bt开源的客户端——xbt client
我部署好了bt tracker, 用bitcomet可以下载. 但xbt client下载不来.torrent资源.
- (转)非阻塞Connect对于select时应注意问题
对于面向连接的socket类型(SOCK_STREAM,SOCK_SEQPACKET)在读写数据之前必须建立连接,首先服务器端socket必须在一个客户端知道的地址进行监听,也就是创建socket之后 ...
- tiny210V2开发板hdmi输出到10.1寸LCD,无图像
tiny210V2开发板hdmi输出到10.1寸LCD,无图像... 用tiny210V2开发板的HDMI接口输出到的10.1寸LCD,LCD无任何现象.说明一下我的情况,我的10.1寸屏LCD是HD ...
- 【Java面试题】50 垃圾回收器的基本原理是什么?垃圾回收器可以马上回收内存吗?有什么办法主动通知虚拟机进行垃圾回收?
1.对于GC来说,当程序员创建对象时,GC就开始监控这个对象的地址.大小以及使用情况. 通常,GC采用有向图的方式记录和管理堆(heap)中的所有对象.通过这种方式确定哪些对象是"可达的&q ...
- thinkphp隐藏模块实例
1.项目中若要隐藏模块的做法 2.配置如下: <?php return array( //'配置项'=>'配置值' 'MODULE_ALLOW_LIST' => array ('Ho ...
- php将汉字转换为拼音和得到词语首字母(一)
<?php /** * 修复二分法查找方法 * 汉字拼音首字母工具类 * 注: 英文的字串:不变返回(包括数字) eg .abc123 => abc123 * 中文字符串:返回拼音首字符 ...