[Poj3744]Scout YYF I (概率dp + 矩阵乘法)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 9552 | Accepted: 2793 |
Description
Input
The First line of each test case is N (1 ≤ N ≤ 10) and p (0.25 ≤ p ≤ 0.75) seperated by a single blank, standing for the number of mines and the probability to walk one step.
The Second line of each test case is N integer standing for the place of N mines. Each integer is in the range of [1, 100000000].
Output
Sample Input
0.5 0.5
Sample Output
0.5000000
0.2500000
分析:
概率dp是需要顺着推的,定义dp[i]表示到i的概率。当i有雷时,dp[i] = 0;
否则 dp[i] = dp[i - 1] * p + dp[i - 1] * (1 - p)
最后输出dp[dis[n] + 1]即行。
因为n很大,转移又固定,可以联想到矩乘 + 快速幂。于是就0MS过了
坑: 输入雷不一定有序,需要排序,精度输出需要%.7f 不能 %.7lf。
AC代码:
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
using namespace std;
int n;
int dis[];
struct fi{
double data[][];
fi(){
for(int i = ;i < ;i++){
for(int j = ;j < ;j++){
data[i][j] = ;
}
}
}
}A,T,O;
inline fi operator *(fi A,fi B){
fi t;
for(int i = ;i < ;i++){
for(int j = ;j < ;j++){
for(int k = ;k < ;k++){
t.data[i][j] += A.data[i][k] * B.data[k][j];
}
}
}
return t;
}
fi cmd(fi C,int k){
fi D = O;
while(k){
if(k & )D = D * C;
k >>= ;
C = C * C;
}
return D;
}
double p;
int main(){
for(int i = ;i < ;i++)O.data[i][i] = 1.0;
while(~scanf("%d %lf",&n,&p)){
T.data[][] = (1.0 - p);
T.data[][] = p;
T.data[][] = 1.0;
T.data[][] = 0.0;
for(int i = ;i < ;i++){
for(int j = ;j < ;j++){
A.data[i][j] = 0.0;
}
}
A.data[][] = 1.0;
for(int i = ;i <= n;i++){
scanf("%d",&dis[i]);
}
sort(dis + ,dis + n + );
for(int i = ;i <= n;i++){
A = A * cmd(T,dis[i] - dis[i - ] - );
A.data[][] = ;
A = A * T;
}
printf("%.7f\n",A.data[][]);
}
}
[Poj3744]Scout YYF I (概率dp + 矩阵乘法)的更多相关文章
- poj3744 Scout YYF I[概率dp+矩阵优化]
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8598 Accepted: 2521 Descr ...
- POJ3744 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...
- poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)
F - Scout YYF I Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
题目链接: http://poj.org/problem?id=3744 Scout YYF I Time Limit: 1000MSMemory Limit: 65536K 问题描述 YYF is ...
- 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 ...
- poj 3744 Scout YYF I(概率dp,矩阵优化)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5020 Accepted: 1355 Descr ...
- BZOJ2553[BeiJing2011]禁忌——AC自动机+概率DP+矩阵乘法
题目描述 Magic Land上的人们总是提起那个传说:他们的祖先John在那个东方岛屿帮助Koishi与其姐姐Satori最终战平.而后,Koishi恢复了读心的能力…… 如今,在John已经成为传 ...
- BZOJ1444[Jsoi2009]有趣的游戏——AC自动机+概率DP+矩阵乘法
题目描述 输入 注意 是0<=P, n , l, m≤ 10. 输出 样例输入 input 1 3 2 2 1 2 1 2 AB BA AA input 2 3 4 2 1 2 1 2 AABA ...
- 【BZOJ1444】[Jsoi2009]有趣的游戏 AC自动机+概率DP+矩阵乘法
[BZOJ1444][Jsoi2009]有趣的游戏 Description Input 注意 是0<=P Output Sample Input Sample Output HINT 30%的 ...
随机推荐
- -bash: mysql: command not found 之 MAC
第一次尝试: ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql 提示:Operation not permitted 再次,加sudo附上管理员权限,依旧 ...
- Javaweb学习笔记2—Tomcat和http协议
今天来讲javaweb的第二个阶段学习. 老规矩,首先先用一张思维导图来展现今天的博客内容. ps:我的思维是用的xMind画的,如果你对我的思维导图感兴趣并且想看到你们跟详细的备注信息,请点击下 ...
- [转]Qt 5.5 操作 Excel 的速度 效率问题
转自:http://blog.csdn.net/li494816491/article/details/50274305 1. QAxObject *_excelObject1 =newQAxObje ...
- css3纯手写loading效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- elasticsearch httpclient认证机制
最近公司单位搬迁,所有的服务都停止了,我负责的elasticsearch不知道怎么回事,一直不能运行呢,因此,我一直在负责调试工作.经过两天的调试工作,我发现新的服务器增加了httpclient认证机 ...
- 关于js中的then(盗)
then()相关的东西包括但不限于:promise,thien.js 虽然还没彻底搞清楚这些个玩意儿,但是 现在知道了 then()是干嘛的了 最主要的,是解决了异步方法立刻返回的问题 这个特性 ...
- 制作JPEGImages出现的bug
我用的是下面这个脚本进行改名字: import os import sys path = "/home/bnrc/py-faster-rcnn/data/VOCdevkit2007/VOC2 ...
- 这就是那个feature map256 256向量
http://blog.csdn.net/XZZPPP/article/details/51582810 在这个特征图上使用3*3的卷积核(滑动窗口)与特征图进行卷积,那么这个3*3的区域卷积后可以获 ...
- 下载GitHub上的dnSpy源码
一.方法 下载GitHub上项目的方法,目前我知道的有四种: 1.用svn软件checkout下载 2.安装git,然后git命令下载 3.直接下载项目压缩包 4.安装GitHub的客户端,然后下载项 ...
- mysql中ibatis的limit动态传参
param.put("pageNo",pageNo); param.put("pageSize",pageSize); sqlMap中的用法 limit $ ...