poj-3744-Scout YYF I-矩阵乘法
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-矩阵乘法的更多相关文章
- poj 3744 Scout YYF I (矩阵)
Description YYF -p. Here is the task, given the place of each mine, please calculate the probality t ...
- poj 3744 Scout YYF I (矩阵快速幂 优化 概率dp)
题目链接 分析&&题意来自 : http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710586.html 题意: 在一条不满地雷的 ...
- poj 3744 Scout YYF I(递推求期望)
poj 3744 Scout YYF I(递推求期望) 题链 题意:给出n个坑,一个人可能以p的概率一步一步地走,或者以1-p的概率跳过前面一步,问这个人安全通过的概率 解法: 递推式: 对于每个坑, ...
- 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,矩阵优化)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5020 Accepted: 1355 Descr ...
- 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+矩阵快速幂 Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- poj 3744 Scout YYF I (可能性DP+矩阵高速功率)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5062 Accepted: 1370 Description YYF i ...
- POJ 3744 Scout YYF I(矩阵快速幂优化+概率dp)
http://poj.org/problem?id=3744 题意: 现在有个屌丝要穿越一个雷区,雷分布在一条直线上,但是分布的范围很大,现在这个屌丝从1出发,p的概率往前走1步,1-p的概率往前走2 ...
- POJ 3744 Scout YYF I (概率dp+矩阵快速幂)
题意: 一条路上,给出n地雷的位置,人起始位置在1,向前走一步的概率p,走两步的概率1-p,踩到地雷就死了,求安全通过这条路的概率. 分析: 如果不考虑地雷的情况,dp[i],表示到达i位置的概率,d ...
随机推荐
- JavaScript 将当地时间转换成其它时区
毫无疑问,用JavaScript脚本可以通过直接查看用户的时钟,方便地在网页上显示本地时间. 但是,如果你想显示不同地区的时间—--例如,如果你的本部在别的国家,你想查看“本国”时间而非当地时间,又该 ...
- python之路 --- python文件模式
文件模式: 打开文件的模式有: r,只读模式(默认). w,只写模式.[不可读:不存在则创建:存在则删除内容:] a,追加模式.[可读: 不存在则创建:存在则只追加内容:] "+&quo ...
- [linx学习篇] ssh远程服务器免密码
第一步:生成密钥.在终端下执行命令: ssh-keygen -t rsa 一路回车,各种提示按默认不要改,等待执行完毕.然后执行: ls ~/.ssh #可以看到两个密钥文件:id_rsa(私钥) i ...
- 矩阵快速幂在ACM中的应用
矩阵快速幂在ACM中的应用 16计算机2黄睿博 首发于个人博客http://www.cnblogs.com/BobHuang/ 作为一个acmer,矩阵在这个算法竞赛中还是蛮多的,一个优秀的算法可以影 ...
- ABP介绍
ABP是ASP.NET Boilerplate Project (ASP.NET样板项目)的简称. ABP 适用的场景:中小规模 WEB 应用开发,可直接使用 ABP 框架. 较大型项目可以在 ABP ...
- C# 条件与&&与条件或||的使用总结
CSDN说明: 条件“或”运算符 (||) 执行 bool 操作数的逻辑“或”运算,但仅在必要时才计算第二个操作数. 件“与”运算符 (&&) 执行其 bool 操作数的逻辑“与”运算 ...
- not exists、left join/is null、not in 行为
测试数据 20:25:52[test](;)> select * from t;+------+------+| id | b |+------+------+| 1 | NUL ...
- 【Luogu】P2569股票交易(单调队列优化DP)
题目链接 首先这题可以肯定的是朴素DP秒出.然后单调队列优化因为没接触过所以不会emmm 而且脑补没补出来 坐等四月省选倒数第一emmm 心态爆炸,偷懒放题解链接 #include<cstdio ...
- ACM程序设计选修课——1036: Hungar的菜鸟赛季(YY)
1036: Hungar的菜鸟赛季 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 20 Solved: 14 [Submit][Status][Web ...
- HDU——1042N!(大数阶乘乘法)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...