矩阵快速幂+概率DP poj 3744
/*
POJ 3744 C++ 0ms 184K
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std; struct Matrix
{
double mat[][];
};
Matrix mul(Matrix a,Matrix b)
{
Matrix ret;
for(int i=;i<;i++)
for(int j=;j<;j++)
{
ret.mat[i][j]=;
for(int k=;k<;k++)
ret.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
}
return ret;
}
Matrix pow_M(Matrix a,int n)
{
Matrix ret;
memset(ret.mat,,sizeof(ret.mat));
for(int i=;i<;i++)ret.mat[i][i]=;
Matrix temp=a;
while(n)
{
if(n&)ret=mul(ret,temp);
temp=mul(temp,temp);
n>>=;
}
return ret;
} int x[];
int main()
{
int n;
double p;
while(scanf("%d%lf",&n,&p)!=EOF)//POJ上G++要改为cin输入
{
for(int i=;i<n;i++) scanf("%d",&x[i]);
sort(x,x+n);
double ans=;
Matrix tt;
tt.mat[][]=p;
tt.mat[][]=-p;
tt.mat[][]=;
tt.mat[][]=;
Matrix temp; temp=pow_M(tt,x[]-);
ans*=(-temp.mat[][]); for(int i=;i<n;i++){
if(x[i]==x[i-])continue;
temp=pow_M(tt,x[i]-x[i-]-);
ans*=(-temp.mat[][]);
}
printf("%.7lf\n",ans);//POJ上G++要改为%.7f
}
return ;
}
矩阵快速幂+概率DP poj 3744的更多相关文章
- poj 3744 矩阵快速幂+概率dp
题目大意: 输入n,代表一位童子兵要穿过一条路,路上有些地方放着n个地雷(1<=n<=10).再输入p,代表这位童子兵非常好玩,走路一蹦一跳的.每次他在 i 位置有 p 的概率走一步到 i ...
- 刷题总结—— Scout YYF I(poj3744 矩阵快速幂+概率dp)
题目: Description YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate int ...
- 2018.10.23 bzoj1297: [SCOI2009]迷路(矩阵快速幂优化dp)
传送门 矩阵快速幂优化dp简单题. 考虑状态转移方程: f[time][u]=∑f[time−1][v]f[time][u]=\sum f[time-1][v]f[time][u]=∑f[time−1 ...
- POJ 2778 DNA Sequence ( AC自动机、Trie图、矩阵快速幂、DP )
题意 : 给出一些病毒串,问你由ATGC构成的长度为 n 且不包含这些病毒串的个数有多少个 分析 : 这题搞了我真特么久啊,首先你需要知道的前置技能包括 AC自动机.构建Trie图.矩阵快速幂,其中矩 ...
- BZOJ2553 Beijing2011禁忌(AC自动机+动态规划+矩阵快速幂+概率期望)
考虑对一个串如何分割能取得最大值.那么这是一个经典的线段覆盖问题,显然每次取右端点尽量靠前的串.于是可以把串放在AC自动机上跑,找到一个合法串后就记录并跳到根. 然后考虑dp.设f[i][j]表示前i ...
- 【矩阵快速幂优化DP】【校内测试】
实际上是水水题叻,先把朴素DP方程写出来,发现$dp[i]$实际上是$dp[i-k]-dp[i-1]$的和,而看数据范围,我们实际上是要快速地求得这段的和,突然就意识到是矩阵快速幂叻. 构建矩阵什么的 ...
- LOJ2325. 「清华集训 2017」小 Y 和恐怖的奴隶主【矩阵快速幂优化DP】【倍增优化】
LINK 思路 首先是考虑怎么设计dp的状态 发现奴隶主的顺序没有影响,只有生命和个数有影响,所以就可以把每个生命值的奴隶主有多少压缩成状态就可以了 然后发现无论是什么时候一个状态到另一个状态的转移都 ...
- HDU5411——CRB and Puzzle——————【矩阵快速幂优化dp】
CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- bzoj1009 [HNOI2008]GT考试——KMP+矩阵快速幂优化DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1009 字符串计数DP问题啊...连题解都看了好多好久才明白,别提自己想出来的蒟蒻我... 首 ...
随机推荐
- 百度网盘无vip高速下载的方法
我拿的是谷歌浏览器做实验 首先下载一个可以改user-agent的插件 我chorm里面下载的是User-Agent Switcher for Chrome插件 将百度网盘的url地址中的baidu. ...
- Educational Codeforces Round 81 (Rated for Div. 2) 题解
过了n天补的题解:D AB就不用说了 C. Obtain The String 思路挺简单的,就是贪心,但是直接贪心的复杂度是O(|s|*|t|),会超时,所以需要用到序列自动机 虽然名字很高端但是就 ...
- MongoDB geonear和文本命令驱动程序2.0
文本查询,q作为查询字符串: coll.FindAsync<Foo>(Builders<Foo>.Filter.Text(q)); 文本查询需要一个文本索引.要从C#创建代码, ...
- eclipse unable to start within 45 seconds
在eclipse4.8.2中运行tomcat8.5项目时,提示出错: Server Tomcat v8.0 Server at localhost was unable to start within ...
- linux - mysql 异常:Ignoring query to other database
问题描述 Ignoring query to other database(忽略其他数据库查询) 问题原因 登录方式错误,登录命令用的是 “mysql -root -p”,应该用命令 “mysql - ...
- js报错 Uncaught TypeError: xxxx.each is not a function
在处理ajax返回的json数组时错误的使用了 list.each(function(){ }); 实际上当遍历json数组是应该使用 $.each(list,function(index,cours ...
- flask操作
models.py class CompanyGoodsModel(Base): id=Column(Integer, primary_key=True) company_id = Column(In ...
- C++-POJ2975-Nim
题目把Nim游戏为什么可以取异或和讲解得十分清楚,建议多读几次,理解一下 再一个,可以把每次异或视为一次取数,因此(k[i]^sg)<k[i]即为一种可行操作 /* Nim is a 2-pla ...
- MySQL | 查看log日志
1. 进入mysql mysql -u用户名 -p密码 2. 开启日志 et global general_log=on: 3. 查看mysql日志文件的路径 show variables like ...
- Execl导出系统
前台代码: <button class="btn btn-warning" type="button" onclick="location.hr ...