f[i]=f[i-1]*p+f[i-2]*(1-p);

正好能够用矩阵加速。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
struct matr
{
double mat[3][3];
friend matr operator *(const matr a,const matr b)
{
matr c;
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
c.mat[i][j]=0;
for(int k=1;k<=2;k++)
{
c.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
}
}
}
return c;
}
friend matr operator +(const matr a,const matr b)
{
matr c;
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
c.mat[i][j]=a.mat[i][j]+b.mat[i][j];
}
}
return a;
}
}st,gg;
matr mul(matr a,int x)
{
matr b;
b.mat[1][1]=b.mat[2][2]=1;
b.mat[1][2]=b.mat[2][1]=0;
while(x)
{
if(x&1)b=b*a;
x=x/2;
a=a*a;
}
return b;
}
double get(int x)
{
if(x<0)return 0;
if(x==0)return 1;
matr re;
re=mul(gg,x);
re=re*st;
return re.mat[2][1];
}
int a[111];
int main()
{
int n;
double p;
while(~scanf("%d%lf",&n,&p))
{
st.mat[1][1]=0; st.mat[1][2]=0;
st.mat[2][1]=1; st.mat[2][2]=0;
gg.mat[1][1]=0; gg.mat[1][2]=1;
gg.mat[2][1]=1-p;gg.mat[2][2]=p;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+n+1);
double ans=1.0;
a[0]=0;
for(int i=1;i<=n;i++)
{
int x=a[i]-a[i-1];
ans=ans*get(x-2);
ans=ans*(1-p);
// cout<<ans<<endl;
}
printf("%.7f\n",ans);
}
return 0;
}

poj-3744-Scout YYF I-矩阵乘法的更多相关文章

  1. poj 3744 Scout YYF I (矩阵)

    Description YYF -p. Here is the task, given the place of each mine, please calculate the probality t ...

  2. poj 3744 Scout YYF I (矩阵快速幂 优化 概率dp)

    题目链接 分析&&题意来自 : http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710586.html 题意: 在一条不满地雷的 ...

  3. poj 3744 Scout YYF I(递推求期望)

    poj 3744 Scout YYF I(递推求期望) 题链 题意:给出n个坑,一个人可能以p的概率一步一步地走,或者以1-p的概率跳过前面一步,问这个人安全通过的概率 解法: 递推式: 对于每个坑, ...

  4. POJ 3744 Scout YYF I 概率dp+矩阵快速幂

    题目链接: http://poj.org/problem?id=3744 Scout YYF I Time Limit: 1000MSMemory Limit: 65536K 问题描述 YYF is ...

  5. poj 3744 Scout YYF I(概率dp,矩阵优化)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5020   Accepted: 1355 Descr ...

  6. poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)

    F - Scout YYF I Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  7. POJ 3744 Scout YYF I

    分段的概率DP+矩阵快速幂                        Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  8. poj 3744 Scout YYF I (可能性DP+矩阵高速功率)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5062   Accepted: 1370 Description YYF i ...

  9. POJ 3744 Scout YYF I(矩阵快速幂优化+概率dp)

    http://poj.org/problem?id=3744 题意: 现在有个屌丝要穿越一个雷区,雷分布在一条直线上,但是分布的范围很大,现在这个屌丝从1出发,p的概率往前走1步,1-p的概率往前走2 ...

  10. POJ 3744 Scout YYF I (概率dp+矩阵快速幂)

    题意: 一条路上,给出n地雷的位置,人起始位置在1,向前走一步的概率p,走两步的概率1-p,踩到地雷就死了,求安全通过这条路的概率. 分析: 如果不考虑地雷的情况,dp[i],表示到达i位置的概率,d ...

随机推荐

  1. Linux inode 之我见

    Linux硬盘组织方式为:引导区.超级块(superblock),索引结点(inode),数据块(datablock),目录块(diredtory block).其中超级块中包含了关于该硬盘或分区上的 ...

  2. [POJ 1002] 487-3279 C++解题报告

        487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 228365   Accepted: 39826 D ...

  3. 忘记MySQL的root密码的解决方法

    经常会有朋友或者同事问起,MySQL 的 root 密码忘了,不知道改怎么办. 其实解决方法很简单,下面是详细的操作步骤. (1)修改配置文件my.cnf,在配置文件[mysqld]下添加skip-g ...

  4. css各属性浏览器的兼容情况

  5. [git 学习篇]git管理的是修改,并非文件

    你会问,什么是修改?比如你新增了一行,这就是一个修改,删除了一行,也是一个修改,更改了某些字符,也是一个修改,删了一些又加了一些,也是一个修改,甚至创建一个新文件,也算一个修改. 为什么说Git管理的 ...

  6. 2017"百度之星"程序设计大赛 - 初赛(A)

    小C的倍数问题  Accepts: 1990  Submissions: 4931  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 327 ...

  7. oracle无参数和带参数的存储过程实例

    SQL中调用存储过程语句:call procedure_name(); 注:调用时”()”是不可少的,无论是有参数还是无参数. 定义对数据库存储过程的调用时1.无参数存储过程:{call proced ...

  8. Java容器jdk1.6 Array

    参考:https://www.cnblogs.com/tstd/p/5042087.html 1.定义 顶层接口collection public interface Collection<E& ...

  9. scikit-learn使用方法

    1.支持向量机 #_*_ coding:utf-8 _*_ from sklearn import datasets from sklearn import svm #装载内部测试数据集 digits ...

  10. android 脱壳 之 dvmDexFileOpenPartial断点脱壳原理分析

    android 脱壳 之 dvmDexFileOpenPartial断点脱壳原理分析 导语: 笔者主要研究方向是网络通信协议的加密解密, 对应用程序加固脱壳技术很少研究, 脱壳壳经历更是经历少之甚少. ...