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 ...
随机推荐
- 在python中对元祖进行排序
在python里你可以对一个元组进行排序.例子是最好的说明: >>> items = [(1, 'B'), (1, 'A'), (2, 'A'), (0, 'B'), (0, 'a' ...
- 由浅入深学习PBR的原理和实现
目录 一. 前言 1.1 本文动机 1.2 PBR知识体系 1.3 本文内容及特点 二. 初阶:PBR基本认知和应用 2.1 PBR的基本介绍 2.1.1 PBR概念 2.1.2 与物理渲染的差别 2 ...
- Leetcode 472.连接词
连接词 给定一个不含重复单词的列表,编写一个程序,返回给定单词列表中所有的连接词. 连接词的定义为:一个字符串完全是由至少两个给定数组中的单词组成的. 示例: 输入: ["cat" ...
- 九度oj 1004
题目1004:Median 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:17536 解决:4860 题目描述: Given an incre ...
- 【Luogu】P2569股票交易(单调队列优化DP)
题目链接 首先这题可以肯定的是朴素DP秒出.然后单调队列优化因为没接触过所以不会emmm 而且脑补没补出来 坐等四月省选倒数第一emmm 心态爆炸,偷懒放题解链接 #include<cstdio ...
- NOJ——聊天止于呵呵(string流重定向+map,水题)
[1645] 聊天止于呵呵 时间限制: 5000 ms 内存限制: 65535 K 问题描述 (现代版)俗话说:流言止于智者,聊天止于呵呵.输入一段聊天记录,你的任务是数一数有 多少段对话“止于呵呵” ...
- BZOJ 4817 [Sdoi2017]树点涂色 ——LCT 线段树
同BZOJ3779. SDOI出原题,还是弱化版的. 吃枣药丸 #include <map> #include <cmath> #include <queue> # ...
- [luoguP2764] 最小路径覆盖问题(最大流 || 二分图最大匹配)
传送门 可惜洛谷上没有special judge,不然用匈牙利也可以过的,因为匈牙利在增广上有一个顺序问题,所以没有special judge就过不了了. 好在这个题的测试数据比较特殊,如果是网络流的 ...
- 刷题总结——doing homework again(hdu1789)
题目: Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot ...
- linux下Apache+Svn环境搭建(五)
在搭建之前先准备好如下包,建议去apache官网去下载:http://httpd.apache.org/ apr-1.4.6.tar.gzapr-util-1.4.1.tar.gzhttpd-2.2. ...