POJ3744(概率dp)
思路:一长段概率乘过去最后会趋于平稳,所以因为地雷只有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)的更多相关文章
- poj3744 (概率DP+矩阵快速幂)
http://poj.org/problem?id=3744 题意:在一条铺满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,10000000 ...
- 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 ...
- POJ3744 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...
- [Poj3744]Scout YYF I (概率dp + 矩阵乘法)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9552 Accepted: 2793 Descr ...
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- 概率DP light oj 1030
t组数据 n块黄金 到这里就捡起来 出发点1 到n结束 点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6 如果满6个的话 否则 ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
随机推荐
- svg矢量图制作工具(Sketsa SVG Editor) v7.1.1 中文免费版
下载地址:https://www.jb51.net/softs/555253.html Sketsa SVG Editor中文版是一款强大好用的矢量图绘制工具,该工具的最大特色就是集成了中文语言,且支 ...
- get_extension_funcs 返回某个模块下的所有函数
array get_extension_funcs ( string $module_name ) (参数必选) 该函数根据 module_name 返回模块内定义的所有函数的 ...
- userData IE
蛮讨厌IE的,因为他常常需要特别照顾,就像DOM Storage(sessionStorage和localStorage)只能支持IE8+,对于以下的只能使用userData. 原理:通过在docum ...
- Grunt 自动编译 Less 文件配置
1.安装Grunt http://www.gruntjs.net/getting-started 2.编辑 package.json 文件 { "name": "Grun ...
- C#中XML解析的增加修改和删除
01添加xml节点 private void AddXml(string image, string title) { XmlDocument xmlDoc = n ...
- codevs 3095 黑心的市长
3095 黑心的市长 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 钻石 Diamond 题目描述 Description A市有一条长Nkm的高速公路.有M个人各自想承包 ...
- Objective-C 中nil/Nil/NULL/NSNull
转自:http://nshipster.cn/nil/ 理解"不存在"的概念不仅仅是一个哲学的问题,也是一个实际的问题.我们是有形宇宙的居民,而原因在于逻辑宇宙的存在不确定性.作为 ...
- 2014年将会受欢迎的IT技能--你有多少哪?
据国外媒体报道,据Global Knowledge等十几家研究机构发布的2014年IT技能和薪金调查报告显示,2014年最受欢迎的十大IT技能如下: 1.编程与应用开发 据美国劳工统计局称,开发者和程 ...
- CNN相关资料
转子http://blog.csdn.net/qianqing13579/article/details/71076261 前言 入职之后,逐渐转到深度学习方向.很早就打算写深度学习相关博客了,但是由 ...
- mysql 自动备份命令
--1.全备 --single-transaction:基于此选项能实现热备InnoDB表 --databases要备份的表名mysqldump -u root -p --single-transa ...