思路:一长段概率乘过去最后会趋于平稳,所以因为地雷只有10个,可以疯狂压缩其位置,这样就不需要矩阵乘优化了。另外初始化f[0] = 0, f[1] = 1,相当于从1开始走吧。双倍经验:洛谷1052.

 for (int i = ; i <= n; i++) {
if (pos[i] - pos[i - ] > ) {
for (int j = n; j >= i; j--)
pos[j] -= (pos[i] - pos[i - ] - );
}
}

这段代码j要倒着写否则先从i开始的话pos[i] - pos[i-1]就变了,我tm居然WA了一板一上午……请叫我绝世大傻逼。

非矩阵版:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef double db; const int maxn = 1e3 + ;
int n, pos[];
db f[maxn];
db p; db solve() {
memset(f, , sizeof f);
f[] = 1.0;
int t = ;
for (int i = ; i <= pos[n]; i++) {
if (i == pos[t]) f[i] = , t++;
f[i + ] += p * f[i];
f[i + ] += (1.0 - p) * f[i];
}
return f[pos[n] + ];
} int main() {
while (scanf("%d%lf", &n, &p) != EOF) {
for (int i = ; i <= n; i++) scanf("%d", &pos[i]);
sort(pos + , pos + + n);
for (int i = ; i <= n; i++) {
if (pos[i] - pos[i - ] > ) {
for (int j = n; j >= i; j--)
pos[j] -= (pos[i] - pos[i - ] - );
}
}
printf("%.7f\n", solve());
}
return ;
}

顺手练一下矩阵,写得low了点:

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <fstream>
#include <bitset>
#define init(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define irep(i, a, b) for (int i = a; i >= b; i--)
using namespace std; typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18; template <typename T> void read(T &x) {
x = ;
int s = , c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') s = -;
for (; isdigit(c); c = getchar())
x = x * + c - ;
x *= s;
} template <typename T> void write(T x) {
if (x < ) x = -x, putchar('-');
if (x > ) write(x / );
putchar(x % + '');
} template <typename T> void writeln(T x) {
write(x);
puts("");
} struct Matrix {
db v[][]; Matrix() {
init(v, );
} friend Matrix operator * (Matrix A, Matrix B) {
Matrix ret;
rep(i, , ) rep(j, , ) rep(k, , )
ret.v[i][j] += A.v[i][k] * B.v[k][j];
return ret;
} friend Matrix operator ^ (Matrix A, int k) {
Matrix ret;
ret.v[][] = ret.v[][] = ;
for (; k; k >>= ) {
if (k & ) ret = ret * A;
A = A * A;
}
return ret;
}
}; int n, pos[];
db p; int main() {
while (~scanf("%d%lf", &n, &p)) {
rep(i, , n) read(pos[i]);
sort(pos + , pos + + n); pos[] = , pos[n + ] = pos[n] + ;
Matrix f, dp;
f.v[][] = ;
rep(i, , n + ) {
int t = pos[i] - pos[i - ];
dp.v[][] = p, dp.v[][] = - p, dp.v[][] = , dp.v[][] = ;
f = f * (dp ^ t);
if (i <= n) f.v[][] = ;
} printf("%.7f\n", f.v[][]);
}
return ;
}

POJ3744(概率dp)的更多相关文章

  1. poj3744 (概率DP+矩阵快速幂)

    http://poj.org/problem?id=3744 题意:在一条铺满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,10000000 ...

  2. POJ-3744 Scout YYF I 概率DP

    题目链接:http://poj.org/problem?id=3744 简单的概率DP,分段处理,遇到mine特殊处理.f[i]=f[i-1]*p+f[i-2]*(1-p),i!=w+1,w为mine ...

  3. POJ3744 Scout YYF I 概率DP+矩阵快速幂

    http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...

  4. [Poj3744]Scout YYF I (概率dp + 矩阵乘法)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9552   Accepted: 2793 Descr ...

  5. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  6. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  7. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  8. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

  9. 概率DP light oj 1030

    t组数据 n块黄金 到这里就捡起来 出发点1 到n结束  点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6  如果满6个的话 否则 ...

  10. hdu 4050 2011北京赛区网络赛K 概率dp ***

    题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...

随机推荐

  1. DIY固件系列教程——实现开机LOGO三屏动画的完全替换【转】

    本文转载自:http://blog.csdn.net/sdgaojian/article/details/9192433 本教程需要用到如下工具:1,7Z压缩工具2,AddCrc32效验工具3,raw ...

  2. hdu1052 田忌赛马 —— 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 错误代码: #include<stdio.h>//田忌赛马,错误版 #include ...

  3. [转]FPGA入门——basys2开发板的伪随机gold码的生成

    本文原创,转载请注明出处:http://www.cnblogs.com/risten/p/4166169.html 1.系统原理 通过频率控制字选择相位步进,产生访问ROM的地址,进而控制DAC的输出 ...

  4. WPF-初始屏幕(SplashScreen)

    本主题介绍如何将启动窗口(也称为“初始屏幕”)添加到 Windows Presentation Foundation (WPF) 应用程序. 添加现有图像作为初始屏幕 创建或查找要用于初始屏幕的图像. ...

  5. 【转载】Unity3D的断点调试功能

    原文链接:http://liweizhaolili.blog.163.com/blog/static/162307442013214485190/    断点调试功能可谓是程序员必备的功能了.Unit ...

  6. ZIP伪加密(deprecated)

    ZIP伪加密 经过伪加密的apk,改成zip格式打开会发现里面的文件都经过了加密. APK实际上是Zip压缩文件,但是Android系统在解析APK文件时,和传统的解压压缩软件在解析Zip文件时存在差 ...

  7. 「IOI1998」「LuoguP4342」Polygon(区间dp

    P4342 [IOI1998]Polygon - 洛谷 题意翻译 题目可能有些许修改,但大意一致 多边形是一个玩家在一个有n个顶点的多边形上的游戏,如图所示,其中n=4.每个顶点用整数标记,每个边用符 ...

  8. bzoj 5072 [Lydsy1710月赛]小A的树——树形dp

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5072 发现对于每个子树,黑点个数确定时,连通块的大小取值范围一定是一段区间:所以考虑只最小化 ...

  9. 你忘记的java的数据类型信息

    java有8种基本数据类型 int long short byte float double char boolean: 三种情况造成数据溢出 无穷大,无穷小, NAN: 常量 声明为final的变量 ...

  10. java中有关socket通信的学习笔记

    最近做的项目中使用到了一些基于java的socket长连接的一些功能,用来穿透有关行业的网闸.用到了也就学习了一下,下面是对学习内容的一个笔记,记录一下也希望有兴趣的同学可以参考一下,加深对javas ...