poj 3744 概率dp+矩阵快速幂
dp[i] | p ,1-p | dp[i-1]
=| |*
dp[i-1] | 1 , 0 | dp[i-2]
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt,x[MAXN],dp[MAXN];
struct Matrix
{
double mat[][];
};
Matrix mul(Matrix a,Matrix b)
{
Matrix ret;
for(int i=;i<;i++)
for(int j=;j<;j++)
{
ret.mat[i][j]=;
for(int k=;k<;k++)
ret.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
}
return ret;
}
Matrix pow_M(Matrix a,int n)
{
Matrix ret;
memset(ret.mat,,sizeof(ret.mat));
for(int i=;i<;i++)ret.mat[i][i]=;
Matrix temp=a;
while(n)
{
if(n&)ret=mul(ret,temp);
temp=mul(temp,temp);
n>>=;
}
return ret;
}
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
double p;
while(scanf("%d%lf",&n,&p)!=EOF)
{
double ans=;
for(i=;i<n;i++) scanf("%d",x+i);
sort(x,x+n);
Matrix a,b;
a.mat[][]=p;
a.mat[][]=-p;
a.mat[][]=;
a.mat[][]=;
b=pow_M(a,x[]-);
ans*=(-b.mat[][]);
for(i=;i<n;i++)
{
if(x[i]==x[i-]) continue;
b=pow_M(a,x[i]-x[i-]-);
ans*=(-b.mat[][]);
}
printf("%.7f\n",ans);
}
}
poj 3744 概率dp+矩阵快速幂的更多相关文章
- Scout YYF I POJ - 3744(概率dp + 矩阵快速幂)
题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * d ...
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
题目链接: http://poj.org/problem?id=3744 Scout YYF I Time Limit: 1000MSMemory Limit: 65536K 问题描述 YYF is ...
- poj3744 (概率DP+矩阵快速幂)
http://poj.org/problem?id=3744 题意:在一条铺满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,10000000 ...
- poj4474 Scout YYF I(概率dp+矩阵快速幂)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4100 Accepted: 1051 Descr ...
- POJ3744 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...
- POJ 3744 Scout YYF I (概率dp+矩阵快速幂)
题意: 一条路上,给出n地雷的位置,人起始位置在1,向前走一步的概率p,走两步的概率1-p,踩到地雷就死了,求安全通过这条路的概率. 分析: 如果不考虑地雷的情况,dp[i],表示到达i位置的概率,d ...
- poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)
F - Scout YYF I Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- bnuoj 34985 Elegant String DP+矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...
- poj 3070 && nyoj 148 矩阵快速幂
poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.n ...
随机推荐
- 基于canvas的图片编辑合成器
在我们日常的前端开发中,经常会要给服务器上传图片,但是局限很大,图片只能是已有的,假设我想把多张图片合成一张上传就需要借助图片编辑器了,但是现在我们有了canvas合成就简单多了 首先我们看图片编辑器 ...
- docker 升级后,配置 idea 连接 docker
[root@A01-R02-I188-87 ~]# docker version Client: Version: 18.06.1-ce API version: 1.24 Go version: g ...
- python设计模式之内置装饰器使用(四)
前言 python内部有许多内建装饰器,它们都有特别的功能,下面对其归纳一下. 系列文章 python设计模式之单例模式(一) python设计模式之常用创建模式总结(二) python设计模式之装饰 ...
- SPI协议及其工作原理浅析【转】
转自:http://www.laoliu-soft.net/category/tech_chap/tech_linux/ 一.概述. SPI, Serial Perripheral Interface ...
- Tomcat参数调优包括日志、线程数、内存【转】
[Tomcat中日志打印对性能测试的影响] 一般都提供了这样5个日志级别: ▪ Debug ▪ Info ▪ Warn ▪ Error ▪ Fatal 由于性能测试需要并发进行压力测试,如果日志级别是 ...
- Metro应用Json数据处理
Windows Phone 8 或者 Windows 8 平台对JSON数据的处理方式基本是一致的,需要使用DataContractJsonSerializer类将对象的实例序列化为JSON字符串,并 ...
- css给奇数行或偶数行添加指定样式
odd表示奇数行,even表示偶数行; tr:nth-child(odd); .table-striped > tbody > tr:nth-child(odd) { background ...
- BootStrap的table表格,栅格系统,form表单的样式
BootStrap BootStrap的简介 1. 什么是Bootstrap 由两个前端设计师开发的一个前端的框架(Html,css,js) 简化了程序员写css的代码 2. 为什么使用B ...
- LeetCode679. 24 Game
You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated ...
- Linux 基础——压缩解压命令
时间过的真快,周末不会学习Linux,每天就是下班后学习.这周工作很忙,要几天总结一次了. 一.处理数据文件 sort dest:将目标文件的内容进行排序,默认是按字符顺序排序的. sort -n d ...