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 ...
随机推荐
- wireshark教程(一)
按照国际惯例,从最基本的说起. 抓取报文: 下载和安装好Wireshark之后,启动Wireshark并且在接口列表中选择接口名,然后开始在此接口上抓包.例如,如果想要在无线网络上抓取流量,点击无线接 ...
- Oracle分页(limit方式的运用)
select * from a_matrix_navigation_map where rowid not in(select rowid from a_matrix_navigation_map w ...
- 透明遮罩图层VS高斯模糊滤镜 效果分析
前端流行布局中最常见的弹出图层有popup, 对话框, tooltip等, 他们都使用了新的图层,但是实现办法各不相同, 有 的是通过半通明的黑白图层实现的, 有的是通过滤镜实现的, 我们来研究一下两 ...
- Entity Framework实体拆分
一.概念 实体拆分:一个实体拆分成多个表,如Product实体,可以拆分成Product和ProductWebInfo两个表,Product表用于存储商品的字符类信息,ProductWebInfo用于 ...
- RTMP规范 消息与消息块
Real Time Messaging Protocol(实时消息传输协议) 应用层协议 RTMP协议中, 基本数据单元称为消息(Message).当RTMP协议在互联网中传输数据的时候,消息会被拆分 ...
- Charles安装包及破解包下载地址
Charles安装包及破解包下载地址 http://xclient.info/s/charles.html?_=baf317d2a9932afca9b32c327f8a34c9
- Windows 10恢复Shift+右键打开命令提示符窗口
导入以下注册表即可. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\Background\shell\cmd1] ...
- YARN : Architecture of Next Generation Apache Hadoop MapReduceFramework
转自:http://blog.csdn.net/colorant/article/details/9146201 == 目标问题 == 下一代的Hadoop框架,支持10,000+节点规模的Hadoo ...
- 登录centos虚拟机后显示-bash-4.1
http://zhidao.baidu.com/link?url=KwpGOdwFw1oxnL71pvPlfRgbRL_IuQeYRzIYJjiDb2SnX0dQye5yUXqHAGSyuD6u2nD ...
- Hello World! 这是我的第一个 CGI 程序
Hello World! 这是我的第一个 CGI 程序上面的 C++ 程序是一个简单的程序,把它的输出写在 STDOUT 文件上,即显示在屏幕上.在这里,值得注意一点,第一行输出 Content-ty ...