【题目链接】

http://poj.org/problem?id=3744

【算法】

概率DP + 矩阵乘法

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i,n;
double p,g,ans;
double x[]; struct Matrix
{
double mat[][];
} m; inline Matrix multipy(Matrix &a,Matrix b)
{
int i,j,k;
Matrix res;
memset(res.mat,,sizeof(res.mat));
for (i = ; i <= ; i++)
{
for (j = ; j <= ; j++)
{
for (k = ; k <= ; k++)
{
res.mat[i][j] += a.mat[i][k] * b.mat[k][j];
}
}
}
return res;
}
inline Matrix power(Matrix a,int n)
{
int i,j;
Matrix res,b = a;
for (i = ; i <= ; i++)
{
for (j = ; j <= ; j++)
{
res.mat[i][j] = (i == j);
}
}
while (n)
{
if (n & ) res = multipy(res,b);
b = multipy(b,b);
n >>= ;
}
return res;
} int main()
{ while (scanf("%d%lf",&n,&p) != EOF)
{
for (i = ; i <= n; i++) scanf("%lf",&x[i]);
sort(x+,x+n+);
m.mat[][] = p; m.mat[][] = - p;
m.mat[][] = ; m.mat[][] = ;
ans = 1.0;
x[] = ;
for (i = ; i <= n; i++)
{
m = power(m,x[i]-x[i-]-);
g = m.mat[][];
ans *= ( - g);
m.mat[][] = p; m.mat[][] = - p;
m.mat[][] = ; m.mat[][] = ;
}
printf("%.7lf\n",ans);
} return ; }

【POJ 3744】 Scout YYF I的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. Beta冲刺-星期三

    这个作业属于哪个课程  <课程的链接>            这个作业要求在哪里 <作业要求的链接> 团队名称 Three cobblers 这个作业的目标 剩余任务预估,分配 ...

  2. Android @Field parameters can only be used with form encoding

    今天在学习Retrofit的时候,当post请求时 public interface NewsDataService { @POST("news/list") Call<Ne ...

  3. 【sqli-labs】 less38 GET -Stacked Query Injection -String based (GET型堆叠查询字符型注入)

    这个直接用union select就可以 http://192.168.136.128/sqli-labs-master/Less-38/?id=0' union select 1,2,3%23 看一 ...

  4. js判断数组中是否包含某个值

    /** * 判断数组中是否包含某个值 * @param arr 数组 * @param str 值 * @returns {boolean} */ function contains(arr, str ...

  5. linux配置 yum 源

    使用 yum 命令安装软件包需要一个yum仓库(即yum源),yum通过客户端(yum命令本身即是yum客户端)去连接yum源服务器,CentOS默认yum源为官方的 http://mirrorlis ...

  6. TCP协议的三次握手、四次挥手

    TCP三次握手 TCP的连接的建立需要发送三个包,一次称为三次握手(Three-way Handshake). 三次握手的目的是连接服务器指定端口,建立TCP连接,并同步连接双方的序列号和确认号并交换 ...

  7. 团体程序设计天梯赛-练习集-L1-030. 一帮一

    L1-030. 一帮一 “一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组.本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后, ...

  8. AD 域服务简介(一)- 基于 LDAP 的 AD 域服务器搭建及其使用(转)

    一.前言 1.1 AD 域服务 什么是目录(directory)呢? 日常生活中使用的电话薄内记录着亲朋好友的姓名.电话与地址等数据,它就是 telephone directory(电话目录):计算机 ...

  9. Ubuntu安装RTX2080显卡驱动

    安装RTX2080显卡驱动 近日新购了一台DELL服务器,用于TensorFlow,由于显卡是另加的,需要安装显卡驱动. 服务器配置 服务器型号:DELL PowerEdge R730 CPU:2*I ...

  10. 从读写分离到 CQRS,张大胖是如何解决性能问题的?

    转自:https://mp.weixin.qq.com/s/rpiYZkxiLKa77OFw8XaBwA 不堪重负的数据库 张大胖公司的数据库已经不堪重负了. 这个系统最早是两个实习生写的, 按照最初 ...