zoukankan      html  css  js  c++  java
  • P2719 搞笑世界杯

    P2719 搞笑世界杯
    我觉得这个难度是假的,如果不知道这个是dp我就做不出来,好吧,知道我也没做出来。。
    f[i][j]表示剩i张A票,j张B票时,最后两张票相同的概率。
    当前的队首有一半的概率选A,一半的概率选B,
    so f[i][j]=0.5*f[i-1][j]+0.5*f[i][j-1]
    答案为f[n][n]

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<queue>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<ctime>
     7 #include<cstring>
     8 #define inf 2147483647
     9 #define For(i,a,b) for(register int i=a;i<=b;i++)
    10 #define p(a) putchar(a)
    11 #define g() getchar()
    12 //by war
    13 //2017.10.17
    14 using namespace std;
    15 int n;
    16 double f[2000][2000];//33M
    17 void in(int &x)
    18 {
    19     int y=1;
    20     char c=g();x=0;
    21     while(c<'0'||c>'9')
    22     {
    23     if(c=='-')
    24     y=-1;
    25     c=g();
    26     }
    27     while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
    28     x*=y;
    29 }
    30 void o(int x)
    31 {
    32     if(x<0)
    33     {
    34         p('-');
    35         x=-x;
    36     }
    37     if(x>9)o(x/10);
    38     p(x%10+'0');
    39 }
    40 int main()
    41 {
    42     in(n);
    43     n>>=1;
    44     For(i,2,n)
    45     f[i][0]=1.0;
    46     For(i,2,n)
    47     f[0][i]=1.0;
    48     For(i,1,n)
    49       For(j,1,n)
    50         f[i][j]=(f[i-1][j]+f[i][j-1])*0.5;
    51     printf("%.4f",f[n][n]);    
    52      return 0;
    53 }
    View Code
  • 相关阅读:
    java四种数组排序
    hadoop安装及配置
    Talend初试,实现定时同步
    JAVA语言概述和基本语法知识点
    Maven项目资源文件打包错误
    Ajax同步和异步
    Nginx + Tomcat 负载均衡
    PLSQL安装配置
    WebStorm 设置光标位置不随意停靠
    Hello Node.js
  • 原文地址:https://www.cnblogs.com/war1111/p/7683696.html
Copyright © 2011-2022 走看看