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 ...
随机推荐
- Android Studio安装踩坑
title: Android Studio安装踩坑 date: 2018-09-07 19:31:32 updated: tags: [Android,Android Studio,坑] descri ...
- Spring配置文件中使用ref local与ref bean的区别
Spring配置文件中使用ref local与ref bean的区别.在ApplicationResources.properties文件中,使用<ref bean>与<ref lo ...
- cURL介绍
1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL 的一些高级特性 ...
- ubuntu安装mysql<服务器>
服务器 阿里云服务器Ubuntu安装mysql 2014-08-22 21:52 | coding云 | 7315次阅读 | 11条评论 这里首先吐槽一下阿里云,我作为公司的唯一懂服务器架设的 ...
- HDU——1233还是畅通工程(克鲁斯卡尔+优先队列)
还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- BZOJ 4553 [Tjoi2016&Heoi2016]序列 ——CDQ分治 树状数组
考虑答案的构成,发现是一个有限制条件的偏序问题. 然后三个维度的DP,可以排序.CDQ.树状数组各解决一维. #include <map> #include <cmath> # ...
- el-select绑定值为对象时,报错[Vue warn]: <transition-group> children must be keyed: <ElTag>
解决方法: <el-select v-model="syncParams.toSlaveList" multiple value-key="ip" pla ...
- javascript之进阶
一 模态框 1 什么是模态框 模态框(Modal)是覆盖在父窗体上的子窗体.指在用户想要对对话框以外的应用程序进行操作时,必须首先对该对话框进行响应.如单击[确定]或[取消]按钮等将该对话框关闭. 2 ...
- 【CF56E】Domino Principle(线性扫描,伪DP)
每块多米诺骨牌所在的位置设为x,每块多米诺骨牌高度为h.如果将x位置上的多米诺骨牌向右翻到,它就可以影响[x+1, x+h-1]范围内的所有多米诺骨牌,让他们也翻到,同时这些被翻到的多米诺骨牌还能影响 ...
- javascript事件捕获机制,dom tree
$(document,"a").on("click",function(){alert(2);return false;}); $("<a> ...