POJ-3744-概率dp+矩阵幂(分段)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10214 | Accepted: 2980 |
Description
Input
Each test case contains two lines.
The First line of each test case is N (1 ≤ N ≤ 10) and p (0.25 ≤ p ≤ 0.75) seperated by a single blank, standing for the number of mines and the probability to walk one step.
The Second line of each test case is N integer standing for the place of N mines. Each integer is in the range of [1, 100000000].
Output
Sample Input
1 0.5
2
2 0.5
2 4
Sample Output
0.5000000
0.2500000
Source
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<time.h>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define debug puts("debug")
#define LL long long
#define pii pair<int,int>
#define eps 1e-12 struct matrix{
double a[][];
matrix& operator*(matrix &tmp){
matrix ans;
memset(ans.a,,sizeof(ans.a));
for(int i=;i<;++i){
for(int j=;j<;++j){
for(int k=;k<;++k){
ans.a[i][j]+=a[i][k]*tmp.a[k][j];
}
}
}
return ans;
}
}A,E;
double qpow(matrix H,int b){
matrix ans=E;
while(b){
if(b&) ans=ans*H;
H=H*H;
b>>=;
}
return ans.a[][];
}
int main()
{
int n,m,i,j,k,t;
int x[];
double P;
E.a[][]=E.a[][]=;
E.a[][]=E.a[][]=;
while(scanf("%d%lf",&n,&P)!=EOF){
A.a[][]=P;
A.a[][]=1.00-P;
A.a[][]=;
A.a[][]=;
for(i=;i<=n;++i) scanf("%d",x+i);
sort(x+,x++n);
bool ok=;
for(i=;i<=n;++i)
if(x[i]-x[i-]==) ok=;
if(ok==||x[]==){
printf("%.7f\n",0.0);
continue;
}
double ans=;
ans=ans*(-P)*qpow(A,x[]-);
for(i=;i<=n;++i){
if(x[i]==x[i-]) continue;
ans=ans*((double)-P)*qpow(A,x[i]-x[i-]-);
}
printf("%.7f\n",ans);
}
return ;
}
POJ-3744-概率dp+矩阵幂(分段)的更多相关文章
- Scout YYF I POJ - 3744(概率dp + 矩阵快速幂)
题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * d ...
- poj 3744 概率dp+矩阵快速幂
题意:在一条布满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,100000000]. 每次前进p的概率前进一步,1-p的概率前进1-p步.问 ...
- poj 3744 概率dp 快速幂 注意排序 难度:2
/* Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5304 Accepted: 1455 De ...
- POJ3744 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...
- hdu 4576(简单概率dp | 矩阵优化)
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle? 感觉很不公平.大家算法都一致,因为我程序没有那 ...
- [Poj3744]Scout YYF I (概率dp + 矩阵乘法)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9552 Accepted: 2793 Descr ...
- BZOJ1444[Jsoi2009]有趣的游戏——AC自动机+概率DP+矩阵乘法
题目描述 输入 注意 是0<=P, n , l, m≤ 10. 输出 样例输入 input 1 3 2 2 1 2 1 2 AB BA AA input 2 3 4 2 1 2 1 2 AABA ...
- bzoj-4870-组合dp+矩阵幂
4870: [Shoi2017]组合数问题 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 829 Solved: 446[Submit][Statu ...
- 【BZOJ1444】[Jsoi2009]有趣的游戏 AC自动机+概率DP+矩阵乘法
[BZOJ1444][Jsoi2009]有趣的游戏 Description Input 注意 是0<=P Output Sample Input Sample Output HINT 30%的 ...
随机推荐
- Java使用极小的内存完成对超大数据的去重计数,用于实时计算中统计UV
Java使用极小的内存完成对超大数据的去重计数,用于实时计算中统计UV – lxw的大数据田地 http://lxw1234.com/archives/2015/09/516.htm Java使用极小 ...
- ping 10.13.5.233
3. 环境 URL选择器 tableView ping 10.13.5.233
- AutoLayout性能不如frame
http://draveness.me/layout-performance.html 复杂视图, 数量超过30个,用autoLayout就比较卡顿了 发现首页类似朋友圈,卡顿的原因应该就是使用了au ...
- ovn-sb 摘要
1.Database Structure Physical network table中包含了和chassis nodes有关的所有信息,包括用于overlay所需的IP地址,支持的tunnel类型以 ...
- IOS使用Core-Plot画折线图
关于Core-Plot的配置.大家能够參考我的上一篇博客:http://1.wildcat.sinaapp.com/?p=99 版权全部.转载请注明原文转自:http://blog.csdn.net/ ...
- 微软官方推出的win10安装或者创建安装u盘的工具
https://www.microsoft.com/zh-cn/software-download/windows10 下载安装后,可根据提示,一步步的安装win10或者创建安装u盘
- Spark Streaming带状态更新
带状态的更新是使用的updateStateByKey方法,里面传入一个函数,函数要自己写,注意需要设置checkpoint import org.apache.spark.streaming.kafk ...
- PAT 1090 Highest Price in Supply Chain[较简单]
1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...
- JDBC连接数据库(一)
原文地址http://www.cnblogs.com/hongten/archive/2011/03/29/1998311.html JDBC连接数据库 创建一个以JDBC连接数据库的程序,包含7个步 ...
- 非线性方程(组):一维非线性方程(一)二分法、不动点迭代、牛顿法 [MATLAB]
1. 二分法(Bisection) 1) 原理 [介值定理] 对于连续的一元非线性函数,若其在两个点的取值异号,则在两点间必定存在零点. [迭代流程] 若左右两端取值不同,则取其中点,求其函数值,取中 ...