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

    前言 项目里面要增加一个应用缓存,原本想着要怎么怎么来整合ehcache和springboot,做好准备配置这个配置那个,结果只需要做三件事: pom依赖 写好一个ehcache的配置文件 在boot ...

  2. 微信小程序自定义下导航页面切换效果的合理写法

    上图::: 导航模板内容页面的定义: <template name="naviBot">   <view class='navwrap t_cen font_26 ...

  3. BZOJ_2208_[Jsoi2010]连通数_强连通分量+拓扑排序+手写bitset

    BZOJ_2208_[Jsoi2010]连通数_强连通分量+拓扑排序+手写bitset Description Input 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i ...

  4. hibernate 中的拦截器EmptyInterceptor接口功能

    Interceptor接口提供了从会话(session)回调(callback)应用程序(application)的机制, 这种回调机制可以允许应用程序在持久化对象被保存.更新.删除或是加载之前,检查 ...

  5. 八、子查询、limit及limit的分页

    1.子查询 定义:select语句中嵌套select语句被称为子查询 select子句可能出现在select.from.where关键字后面,如下: A.将一个表的查询结果当做是过滤条件 B.将一个表 ...

  6. Spring创建对象的三种方式以及创建时间

    创建对象的三种方式: 1.采用默认的构造函数创建 2.采用静态工厂方法 1.写一个静态工厂方法类 public class HelloWorldFactory { public static Hell ...

  7. P-Function

    题意: 对于集合 $S = {1, 2, ...., n}$ , 定义函数 $F(x) = y, x, y$ 属于 $S$,对于任何 $x$ 属于 $S$, 有 $F(F...F(x)) = x$, ...

  8. HDOj-1425

    sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. docker三剑客之一docker compose

    compose有两个重要的概念: 服务(service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实例 项目(project):由一组关联的应用容器组成的一个完整业务单元,在docker- ...

  10. UVa 557 Burger (概率+递推)

    题意:有 n 个牛肉堡和 n 个鸡肉堡给 2n 个客人吃,在吃之前抛硬币来决定吃什么,如果剩下的汉堡一样,就不用投了,求最后两个人吃到相同的概率. 析:由于正面考虑还要要不要投硬币,太麻烦,所以我们先 ...