| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
根本不用矩阵和快速幂啊//根据递推公式观察数据发现,超过步数100以后的概率几乎等于一个和p有关的常数,
//所以可以直接认为走的步数大于100时的概率等于走到第99步的概率
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int cmp(int a,int b)
{
return a<b;
}
int main()
{
double p;
int n;
while(scanf("%d%lf",&n,&p)!=EOF)
{
double dp[100]={0};
dp[1]=1;
dp[0]=0;
for(int i=2;i<=99;i++) dp[i]=dp[i-1]*p+dp[i-2]*(1-p);
int i;
int pos[20];
for(i=0;i<n;i++)scanf("%d",pos+i);
sort(pos,pos+n,cmp) ;
int now=1;
double r=1;
for(i=0;i<n;i++)
{
if(pos[i]-now>=99) r*=dp[99]*(1-p);
else r*=dp[pos[i]-now]*(1-p);
now=pos[i]+1;
}
printf("%.7f\n",r);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator