poj-3744-Scout YYF I-矩阵乘法
来源:互联网 发布:车牌识别软件下载 编辑:程序博客网 时间:2024/06/05 16:37
f[i]=f[i-1]*p+f[i-2]*(1-p);
正好可以用矩阵加速。。。。
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<vector>using namespace std;struct matr{ double mat[3][3]; friend matr operator *(const matr a,const matr b) { matr c; for(int i=1;i<=2;i++) { for(int j=1;j<=2;j++) { c.mat[i][j]=0; for(int k=1;k<=2;k++) { c.mat[i][j]+=a.mat[i][k]*b.mat[k][j]; } } } return c; } friend matr operator +(const matr a,const matr b) { matr c; for(int i=1;i<=2;i++) { for(int j=1;j<=2;j++) { c.mat[i][j]=a.mat[i][j]+b.mat[i][j]; } } return a; }}st,gg;matr mul(matr a,int x){ matr b; b.mat[1][1]=b.mat[2][2]=1; b.mat[1][2]=b.mat[2][1]=0; while(x) { if(x&1)b=b*a; x=x/2; a=a*a; } return b;}double get(int x){ if(x<0)return 0; if(x==0)return 1; matr re; re=mul(gg,x); re=re*st; return re.mat[2][1];}int a[111];int main(){ int n; double p; while(~scanf("%d%lf",&n,&p)) { st.mat[1][1]=0; st.mat[1][2]=0; st.mat[2][1]=1; st.mat[2][2]=0; gg.mat[1][1]=0; gg.mat[1][2]=1; gg.mat[2][1]=1-p;gg.mat[2][2]=p; for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+n+1); double ans=1.0; a[0]=0; for(int i=1;i<=n;i++) { int x=a[i]-a[i-1]; ans=ans*get(x-2); ans=ans*(1-p); // cout<<ans<<endl; } printf("%.7f\n",ans); } return 0;}
0 0
- poj-3744-Scout YYF I-矩阵乘法
- poj 3744 Scout YYF I 概率dp+矩阵乘法
- [概率dp 矩阵乘法] poj 3744 Scout YYF I
- poj 3744 Scout YYF I 矩阵
- poj 3744 Scout YYF I (矩阵乘法+概率与期望DP)
- POJ 3744 Scout YYF I Scout YYF I (递推+矩阵快速幂)
- poj 3744 Scout YYF I
- poj 3744 Scout YYF I
- poj 3744 Scout YYF I
- POJ 3744 Scout YYF I
- POJ 3744 Scout YYF I
- POJ 3744 Scout YYF I
- POJ 3744 Scout YYF I
- POJ 3744 Scout YYF I
- POJ 3744 Scout YYF I
- poj #3744 Scout YYF I
- POJ 3744 Scout YYF I
- POJ 3744 Scout YYF I
- bzoj1611[Usaco2008 Feb]Meteor Shower流星雨
- Swift字典
- 气象雷达地物杂波产生的原因
- 如何敏捷架构
- INFINEON(英飞凌)样片申请与经验
- poj-3744-Scout YYF I-矩阵乘法
- 如何使用 CCache 进行 Cocos2d-x 编译加速
- IO编程——文件创建
- Eclipse断点调试
- Eclipse中异常断点问题
- PHP 配置open_basedir,让各虚拟站点独立运行
- PHP 配置文件中open_basedir选项作用
- 都是php_admin_value open_basedir惹的祸
- IO编程——文件输入输出