POJ 3744 Scout YYF I(概率DP+数学)
来源:互联网 发布:编程语言趋势 编辑:程序博客网 时间:2024/05/29 04:48
不考虑地雷,设f[i]为在i位置上的概率。有f[i] = p * f[i-1] + (1 - p) * f[i-2]。
考虑地雷的话分段算就好了,然而这个问题的关键在于怎么求这个f[i]。
开始看见这个用的矩阵快速幂,,,结果T了【话说别人也有这样做没T的,但看了半天不知道怎么优化
所以就打算求f[i]通项【就是靠数学咯
算出来f[n] = f[1] * (1 - (p - 1)^n) / (2 - p)。
然后再用快速幂就过了!!而且是0ms!!!
代码:
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int maxn = 15;int a[maxn],n;double p;double mod_pow(double a,int k){ double res = 1; while(k){ if(k & 1) res = res * a; a *= a; k >>= 1; } return res;}int main(){ while(~scanf("%d%lf",&n,&p)){ for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); if(a[0] == 1){ printf("%.7f\n",0); continue; } int k; double f = 1; for(int i=0;i<n;i++){ if(i == 0) k = a[i] - 1; else k = a[i] - a[i-1] - 1; f = f * (1 - mod_pow(p-1,k)) / (2 - p); f = f * (1 - p); } printf("%.7f\n",f); } return 0;}
0 0
- POJ 3744 Scout YYF I(概率DP+数学)
- poj 3744 Scout YYF I 概率dp
- POJ 3744 Scout YYF I [概率DP]
- POJ 3744|Scout YYF I|概率DP
- POJ 3744 Scout YYF I 概率DP
- 概率DP POJ 3374 Scout YYF I
- poj 3744 Scout YYF I(概率DP&矩阵快速幂)
- poj 3744 Scout YYF I(概率dp+矩阵快速幂)
- POJ 3744 Scout YYF I 概率DP + 矩阵快速幂
- poj 3744 Scout YYF I(概率dp+矩阵快速幂)
- Poj 3744 Scout YYF I (概率DP 矩阵优化)
- Poj 3744 Scout YYF I 概率DP+快速幂
- poj 3744 Scout YYF I(矩阵优化概率DP)
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
- POJ 3744 Scout YYF I 概率dp 矩阵快速幂
- Poj 3744 Scout YYF I(矩阵概率DP)
- POJ 3744 Scout YYF I (概率DP+矩阵快速幂)
- 【POJ】3744 Scout YYF I (概率DP+矩阵优化)
- URL乱码问题
- 怎样学好ASP.NET技术
- 黑马程序员——Java基础——多线程(一)
- mvc4的传值方式
- 数据结构之红黑树(一)——基础分析
- POJ 3744 Scout YYF I(概率DP+数学)
- Eclipse 报 “Exception in thread "main" java.lang.OutOfMemoryError: Java heap space ”错误的解决
- stm32F411 SPI3 无输出
- 使用UIActionSheet
- 浏览器兼容css设置
- Linux命令free详解
- 7月10日 使用CTE MSDN
- Sql Server 中一个非常强大的日期格式化函数
- sqlite3 not found的解决办法