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 ...
随机推荐
- dubbo doc入门文档
dubbo document http://dubbo.apache.org/zh-cn/docs/user/references/xml/dubbo-protocol.html
- Educational Codeforces Round 36 (Rated for Div. 2)
A. Garden time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- SpringMVC对于跨域访问的支持
原文地址:http://docs.spring.io/spring/docs/5.0.0.RC2/spring-framework-reference/web.html#mvc-introductio ...
- sql语句执行时算术运算导致溢出。
执行sql语句时报错: 用户代码未处理 System.OverflowException HResult=-2146233066 Message=算术运算导致溢出. 文章:https://bbs.cs ...
- 九度oj 题目1171:C翻转
题目描述: 首先输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据. 操作类型有四种: 1 2 表示:90度,顺时 ...
- 快速samba配置
apt-get install samba smbpasswd -a user 如果需要写权限 [homes] read only = no
- cf- 297 < a >--字符串操作技巧
A. Vitaliy and Pie time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- hihoCoder #1157 建造金字塔
这道题我想了一天才想清楚做法.AC 了之后去看别人写的题解,都是三言两语意识流式描述,我并不能读懂.我觉得很自卑,为何人家解这道题如此轻松.不过,我还是决定把我的解法写下来,并且一定要写清楚. 思路 ...
- HDU——2723Electronic Document Security(STL map嵌套set做法)
Electronic Document Security Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- [BZOJ4318] WJMZBMR打osu! / Easy (期望DP)
题目链接 Solution Wa,我是真的被期望折服了,感觉这道题拿来练手正好. DP的难度可做又巧妙... 我们定义: \(f[i]\) 代表到第 \(i\) 次点击的时候的最大答案. \(g[i] ...