POJ 3744 Scout YYF I 概率DP matrix 一开始考虑错误TLE了
2013-04-14 20:43
363 查看
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; //高精度注意-0.000000 //有序无序输入要注意啊 struct matrix { int n,m; double mat[2][2]; void clear(void) { memset(mat,0,sizeof(mat)); } void get_e(void) { int i=0; clear(); for(i=0;i<n;i++)mat[i][i]=1; } matrix() { clear(); } matrix(int x,int y):n(x),m(y) { clear(); } }; matrix operator*(const matrix &a,const matrix &b) { int i,j,k; matrix ret(a.n,b.m); for(k=0;k<a.m;k++) for(i=0;i<a.n;i++) if(a.mat[i][k]!=0) for(j=0;j<b.m;j++) ret.mat[i][j]+=a.mat[i][k]*b.mat[k][j]; return ret; } matrix mypow(matrix a,int x) { matrix ret(a.n,a.m); if(x<0)return ret; ret.get_e(); while(x) { if(x&1)ret=ret*a; a=a*a; x>>=1; } return ret; } const int LMT=12; int pos[LMT]; int main(void) { int n; double p,ans; matrix tem(2,1),use(2,2); while(~scanf("%d%lf",&n,&p)) { for(int i=1;i<=n;++i) scanf("%d",&pos[i]); sort(pos,pos+n+1); tem.clear(); tem.mat[1][0]=1.0; use.mat[1][1]=p; use.mat[1][0]=1-p; use.mat[0][1]=1; for(int i=1;i<=n;i++) { ans=(mypow(use,pos[i]-pos[i-1]-2)*tem).mat[1][0]; ans*=(1-p); tem.clear(); tem.mat[1][0]=ans; } if(ans<0)ans=0; printf("%.7f\n",ans); } return 0; }一开始考虑错误,TLE
相关文章推荐
- poj 3744 Scout YYF I (矩阵快速幂 优化 概率dp)
- POJ 3744 Scout YYF I 详细题解(矩阵优化概率DP)水题
- POJ 3744 Scout YYF I(概率DP+数学)
- poj 3744 Scout YYF I(概率dp,矩阵优化)
- POJ 3744 Scout YYF I 概率DP
- POJ 3744 Scout YYF I(概率Dp)
- POJ 3744 Scout YYF I (矩阵优化,分段计算的概率DP)
- POJ 3744 Scout YYF I(概率DP)
- POJ 3744 Scout YYF I(矩阵优化的概率DP)
- POJ-3744 Scout YYF I 概率DP
- poj 3744 Scout YYF I(矩阵优化概率DP)
- POJ 3744|Scout YYF I|概率DP
- POJ 3744 Scout YYF I (矩阵优化的概率DP)
- [概率dp 矩阵乘法] poj 3744 Scout YYF I
- POJ 3744 Scout YYF I 概率dp+矩阵加速
- poj 3744 Scout YYF I(概率dp+矩阵快速幂)
- POJ 3744:Scout YYF I 很好的一道概率题
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
- POJ 3744 Scout YYF 1(概率递推)
- POJ 3744 Scout YYF(概率DP+矩阵快速幂)