poj3744 (概率DP+矩阵快速幂)
http://poj.org/problem?id=3744
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std; typedef long long ll; typedef vector<double>vec;
typedef vector<vec >mat;
int n;
double p,T1,T2,pT1,pT2;
mat mul(mat &A , mat &B)
{
mat C(A.size(),vec(B.size())); for(int i= ; i<A.size() ; i++)
{
for(int k= ; k<B.size() ; k++)
{
if(A[i][k]==) continue;
for(int j= ; j<B[].size() ; j++)
{
if(B[k][j]==) continue;
C[i][j]=(C[i][j] + A[i][k]*B[k][j]);
}
}
}
return C;
}
mat qpow(mat A,ll n)
{
mat B(A.size(),vec(A.size()));
for(int i= ; i<A.size() ; i++)
B[i][i]=;
while(n>)
{
if(n&)
B=mul(B,A);
A=mul(A,A);
n>>=;
}
return B;
}
double so(int len)
{
mat A(,vec());
A[][]=p;A[][]=-p;
A[][]=;A[][]=;
A = qpow(A,len-);
double T=A[][]*p+A[][];
return T;
}
int x[];
bool vis[];
double dp[];
int main()
{
while(~scanf("%d%lf",&n,&p))
{
int Max=-;
for(int i= ; i<=n ; i++)
scanf("%d",&x[i]),vis[x[i]]=,Max=max(Max,x[i]);
dp[]=;
dp[]=p;
if(vis[]) dp[]=;
if(vis[]) dp[]=;
for(int i= ; i<=Max+ ; i++)
{ dp[i]=dp[i-]*p + dp[i-]*(-p);
if(vis[i]) dp[i]=;
}
printf("%0.7f\n",dp[Max+]); }
}
poj3744 (概率DP+矩阵快速幂)的更多相关文章
- poj4474 Scout YYF I(概率dp+矩阵快速幂)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4100 Accepted: 1051 Descr ...
- 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 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...
- poj 3744 概率dp+矩阵快速幂
题意:在一条布满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,100000000]. 每次前进p的概率前进一步,1-p的概率前进1-p步.问 ...
- 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 ...
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
随机推荐
- mooc-IDEA 列操作--005
十一.IntelliJ IDEA -列操作 实例:根据HTTP请求JSON文件,生成一个枚举类 Step1:创建一个枚举类,把要转换的JSON串粘贴进来. 最终要实现效果 Step2:选中第一个100 ...
- chineseocr项目的配置阶段出现的问题及解决方案
chineseocr为GitHub上的一个开源项目,主要使用yolos,crnn等深度学习框架训练好后的模型使用.测试结果发现,不管是针对文本文件.表格文件.还是场景图,如身份证火车票,识别效果都比较 ...
- SpringBoot使用RestTemplate 摘要认证
SpringBoot使用RestTempate SpringBoot使用RestTemplate摘要认证 SpringBoot使用RestTemplate基础认证 SpringBoot使用RestTe ...
- winCE 获取路径信息
最近在做一个SAP的winCE扫描枪项目,采用C#开发,不过在获取路径是采用了常用的System.IO.Directory.GetCurrentDirectory, 并不能使用:查询后了解到winCE ...
- vs2015上编译QT程序的环境搭建
下载相对应版本的QT(以QT5.7.0为例),进入网站http://download.qt.io/archive/qt/5.7/5.7.0/,下载MSVC版本QT,我的系统是64位,VS版本是2015 ...
- Codeforces 843D (Dijkstra算法的优化,动态最短路)
题面 (http://codeforces.com/problemset/problem/843/D) 题目大意: 给定一张带权无向图,有q次操作 操作有两种 1 v 询问1到v的最短路 2 c 将边 ...
- CSRF verification failed. Request aborted.错误解决办法
在Django项目的页面,提交form表单POST请求时,会出现报错:CSRF verification failed. Request aborted. 需要在form表单中加:{% csrf_to ...
- CSS制作垂直口风琴2
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Windows 中下载 Android Q 源码
1. 安装软件 1.1. 安装 git A.git官网下载:https://git-scm.com/downloads/ 安装git到如下路径 C:/Program Files/Git B.图 ...
- SSM商城系统开发笔记-配置01-web.xml
先占坑 慢慢填, 商城系统使用主体框架:Spring + Spring MVC + Mybatis 其他框架: 日志: slf4j + logback <!DOCTYPE web-app PUB ...