#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 5
using namespace std;
typedef double i64;
i64 a[MAX][MAX], b[MAX][MAX], c[MAX][MAX], buff[MAX][MAX], vec[MAX];
void matCpy(i64 a[MAX][MAX], i64 b[MAX][MAX], int n) {
int i, j;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
a[i][j] = b[i][j];
}
}
}
void norm(i64 a[MAX][MAX], int n) {
int i, j;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
if(i==j) a[i][j]=1;
else a[i][j]=0;
}
}
}
void matMul(const i64 a[MAX][MAX], const i64 b[MAX][MAX], i64 c[MAX][MAX], int n) {
int i, j, k;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
for (c[i][j] = k = 0; k < n; ++k) {
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) ;
}
}
}
}
void matPow(i64 a[MAX][MAX], int b, i64 c[MAX][MAX], int n) {
for (norm(c, n); b; b >>= 1) {
if (b & 1) {
matMul(c, a, buff, n);
matCpy(c, buff, n);
}
matMul(a, a, buff, n);
matCpy(a, buff, n);
}
}
int loc[15];
int main(){
int n;
double p;
double ans;
int flag;
while(scanf("%d%lf",&n,&p)!=EOF)
{
loc[0]=0;
flag=1;
for(int i=1;i<=n;i++) scanf("%d",&loc[i]);
sort(loc,loc+1+n);
for(int i=1;i<n;i++)
{
if(loc[i]+1==loc[i+1])
{
flag=0;
break;
}
}
if(!flag||loc[1]==1)
{
printf("0.0000000\n");
continue;
}
ans=1.;
for(int i=1;i<=n;i++)
{
a[0][0]=p,a[0][1]=1-p;
a[1][0]=1,a[1][1]=0;
matPow(a, loc[i]-loc[i-1]-1, b, 2);
ans*=(1-b[0][0]);
}
printf("%.7lf\n",ans);
}
return 0;
}
POJ 3744 Scout YYF I
最新推荐文章于 2019-09-18 20:25:24 发布