zoukankan      html  css  js  c++  java
  • cdoj 邱老师看电影

    //第一次写概率dp

    //写成记忆化搜索的形式比递推要更方便易懂

    //不过好像还是可以写成递推的形式的 但是比较那个……

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<queue>
     8 #include<vector>
     9 #include<map>
    10 #include<stack>
    11 #include<string>
    12 
    13 using namespace std;
    14 
    15 int w,b;
    16 double f[1007][1007];
    17 
    18 double dfs(int w,int b){
    19     if (w==0) return 0;
    20     if (b==0) return 1;
    21     if (f[w][b]>=0) return f[w][b];
    22     f[w][b]=(double)w/(double)(w+b);
    23     if (w+b>=3){
    24             double tmp=((double)(b)/double(w+b))*((double)(b-1)/(double)(w+b-1));
    25             if (b>=3) f[w][b]=f[w][b]+(tmp*((double)(b-2)/(double)(w+b-2))*dfs(w,b-3));
    26             if (w>=1) f[w][b]=f[w][b]+(tmp*((double)(w)/(double)(w+b-2))*dfs(w-1,b-2));
    27     }
    28     return f[w][b];
    29 }
    30 
    31 int main(){
    32     scanf("%d%d",&w,&b);
    33     for (int i=0;i<=w;i++){
    34             for (int j=0;j<=b;j++){
    35                     f[i][j]=-1;
    36             }
    37     }
    38     printf("%.9lf
    ",dfs(w,b));
    39     return 0;
    40 }
    41 /*
    42 1 3
    43 */
  • 相关阅读:
    mongoDB安装配置
    linux-批量修改目录下后缀shell
    备份mysql的shell
    mysql_DML_索引、视图
    mysql_存储过程
    mysql_备份_mysqldump
    mysql_DCL_grant/revoke
    mysql_DML_select_子查询
    mysql_DML_select_union
    mysql_DML_select_聚合join
  • 原文地址:https://www.cnblogs.com/baby-mouse/p/4508683.html
Copyright © 2011-2022 走看看