思路:一长段概率乘过去最后会趋于平稳,所以因为地雷只有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. codeforces776E

    传送门 这题看着很唬人,但实际上是道水题... f[n]通过打表或证明,可以发现就是欧拉函数,g[n]恒等于n,所以题目的意思就是让你求n的k次欧拉函数. 可以发现实际上k次欧拉函数,n的数值减小得很 ...

  2. flex平分测试

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  3. FFmpeg big changes. ffmpeg 接口的一些改变

    Big changes have been made from FFmpeg 0.5.1… Refer to http://cekirdek.pardus.org.tr/~ismail/ffmpeg- ...

  4. javabean学习

    javabean是一种可重复使用且跨平台的软件组件.他可以分为:客户界面组件(UI,user interface)和没有用户界面,主要负责处理事务(如,数据处理.操作数据库等)地javabean ja ...

  5. 如何查看智能手机的IP地址

      1.  外网IP IP地址可简单分为两类.外网IP或称公网IP是用来在Internet上唯一标识你的设备的.如果你通过GPRS或者3G技术接入互联网的话(通过运营商网络),那么你也可以通过下面的方 ...

  6. 通过 :hover 伪元素控制其他元素

    ---代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...

  7. Python:元组

    元组:只读,不能修改,使用小括号 创建元组: tup1 = ('physics', 'chemistry', 1997, 2000) tup2 = (1, 2, 3, 4, 5 ) tup3 = &q ...

  8. C++中对类的提前引用声明注意事项

    //或许,友元是VC++6.0心里永远的痛,对于这个BUG我一直很介意.//注:这个程序在VC++6.0里是行不通的,在VS2008里是可以的.#include <iostream> #i ...

  9. pytest用例setup和teardown

    函数式以下两种: setup_function/teardown_function  每个用例开始和结束调用一次 setup_module/teardown_module     setup_modu ...

  10. VS2008编了个MFC对话框,编译链接都没有问题,但是运行出来的对话框完全不能点击

    误将整个对话框的属性中disable选为“True”,对话框不可用,选为false即可