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 ...
随机推荐
- 2017ACM暑期多校联合训练 - Team 1 1006 HDU 6038 Function (排列组合)
题目链接 Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m ...
- react CRA antd 按需加载配置 lessloader
webpack配置 webpack.config.dev.js, webpack.config.prod同理. 'use strict'; const autoprefixer = require(' ...
- js布尔值转化
JavaScript 预期某个位置应该是布尔值,会将该位置上现有的值自动转为布尔值.转换规则是除了下面六个值被转为false,其他值都视为true. undefined null false 0 Na ...
- 解决pl/sq可视化工具的中文乱码问题
解决pl/sql中文乱码问题 问题:pl/sql的中文都显示为“?”,怎么能显示成中文呢? 1. 执行sql语句 select * from V$NLS_PARAMETERS NLS_LANGUAG ...
- WordPress的SEO插件——WordPress SEO by yoast安装及使用
插件:WordPress SEO by yoast 使用方法: 做好网站SEO一直是站长们的愿望,说简单也简单,但是说难也难,因为需要注意的地方太多,一个不小心被百度K了你都不知道怎么回事.这里和大家 ...
- callee与caller
1.callee arguments.callee表示当前函数,使用于递归 function factorial(num){ if(num<=1){ return 1; }else{ retur ...
- SpringMVC可以配置多个拦截后缀*.action和.do等
首先介绍一下.do和.action的区别: struts早期的1版本,以.do为后缀. 同时spring的MVC也是以.do为后缀. 几年前struts收购鼎鼎大名的webwork2和开发团队后,将w ...
- linux initcall 介绍 (转自http://blog.csdn.net/fenzhikeji/article/details/6860143)
现在以module_init为例分析initcall在内核中的调用顺序 在头文件init.h中,有如下定义: #define module_init(x) __initcall(x); 很明显 ...
- Mysql存储之原生语句操作(pymysql)
Mysql存储之原生语句操作(pymysql) 关系型数据库是基于关系模型的数据库,而关系模型是通过二维表时实现的,于是构成了行列的表结构. 表可以看作是某个实体的集合,而实体之间存在联系,这个就需要 ...
- rust 入门
hello rust fn main() { println!("Hello, world!"); } 从hello world入手,rust的语法是比较简洁. 在mac os中, ...