【题目链接】

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. C# 多线程系列(四)

    Parallel类 Parallel类定义了for.foreach和invoke的静态方法.Parallel类使用多个任务,因此使用多个线程来完成这个作业. Parallel.For Parallel ...

  2. mvc3结合spring.net-依赖注入

    namespace Tuzi.Models.IService { public interface IPersonService { string say(string words); } names ...

  3. 元信息标记---meta

    位于<head></head>之间 1.设置页面关键字: <meta name="keywords" content="输入具体关键字&qu ...

  4. 关于OpenCV的Mat画图问题

    由于OpenCV的java版本画图有太多错误,只能自己编写画图的代码,在一个函数中,编写出画圆和深度距离的代码, 代码如下: public int CircleMyMat(Mat Show, Poin ...

  5. 使用NDK编译VTK

    VTK提供了对安卓的CMAKE编译支持,其介绍文件在源代码根目录下的 "/cmake/android.toolchain.cmake". 对Wndows的编译自持描述为: 注意:但 ...

  6. DOM学习之充实文档内容

    HTML代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...

  7. 使用yum update更新文件系统时不更新内核的方法

    CentOS使用yum update更新时不升级内核 cp /etc/yum.conf    /etc/yum.confbak 方法一.修改yum的配置文件 vi /etc/yum.conf  在[m ...

  8. 磁盘及文件系统管理(以及btrfs)

    Linux系统管理 磁盘分区及文件系统管理 raid lvm 网络属性管理 程序包管理 sed及awk 进程查看和管理 内核管理(内核的编译和安装) 系统启动流程 定制,编译内核,busybox 系统 ...

  9. PHP过滤html注释

    过滤html注释: 所谓过滤,不过是字符串的匹配与替换,这里我们用到的正则匹配替换函数preg_replace(reg,replace,string);,PHPer都清楚,这个函数的关键在于reg的精 ...

  10. 用户输入input函数和代码注释

    一.读取用户输入 py3中input()读取用户输入,输出全部是默认str字符串数据类型,一般将其赋值变量,用户输入才继续往下走程序.(py2的不同已单独列出随笔) 二.注释 注释的作用:代码量大的时 ...