题目链接:http://poj.org/problem?id=1322

题意:

思路:

double C[N][N];

void init()
{
    C[0][0]=1;
    int i,j;
    for(i=1;i<N;i++)
    {
        C[i][0]=C[i][i]=1;
        for(j=1;j<i;j++) C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
}

double Pow(double a,int b)
{
    double ans=1;
    while(b)
    {
        if(b&1) ans*=a;
        a=a*a;
        b>>=1;
    }
    return ans;
}

int n,m,c;

double cal()
{
    double positive[N],negative[N],a[N],b[N];
    double temp1,temp2;
    int i,j,k;
    for(i=0;i<=c;i++) positive[i]=negative[i]=a[i]=b[i]=0;
    temp1=Pow(0.5,m);
    for(i=0;i<=m;i++)
    {
        j=i-(m-i);
        if((m-i)&1) temp2=-temp1;
        else temp2=temp1;
        if(j>=0) a[j]+=temp2*C[m][i];
        else b[-j]+=temp2*C[m][i];
    }
    temp1=Pow(0.5,c-m);
    for(i=0;i<=c-m;i++)
    {
        temp2=temp1*C[c-m][i];
        for(j=0;j<=m;j++)
        {
            k=j+i-(c-m-i);
            if(k>=0) positive[k]+=temp2*a[j];
            else negative[-k]+=temp2*a[j];
        }
        for(j=0;j<=m;j++)
        {
            k=-j+i-(c-m-i);
            if(k>=0) positive[k]+=temp2*b[j];
            else negative[-k]+=temp2*b[j];
        }
    }
    double ans=0;
    for(k=1;k<=c;k++)
    {
        if(n&1) negative[k]=-negative[k];
        ans+=C[c][m]*Pow(1.0*k/c,n)*(positive[k]+negative[k]);
    }
    return ans;
}

int main()
{
    init();
    Rush(c)
    {
        if(!c) break;
        RD(n,m);
        if((n-m)%2||m>c||m>n) puts("0.000");
        else if(n==0&&m==0) puts("1.000");
        else PR(cal());
    }
}

  

POJ 1322 Chocolate(母函数)的更多相关文章

  1. POJ 1322 Chocolate

    Chocolate Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8245   Accepted: 2186   Speci ...

  2. poj 1322 Chocolate (概率dp)

    ///有c种不同颜色的巧克力.一个个的取.当发现有同样的颜色的就吃掉.去了n个后.到最后还剩m个的概率 ///dp[i][j]表示取了i个还剩j个的概率 ///当m+n为奇时,概率为0 # inclu ...

  3. Solution -「ACM-ICPC BJ 2002」「POJ 1322」Chocolate

    \(\mathcal{Description}\)   Link.   \(c\) 种口味的的巧克力,每种个数无限.每次取出一个,取 \(n\) 次,求恰有 \(m\) 个口味出现奇数次的概率. \( ...

  4. 经典DP 二维换一维

    HDU 1024  Max Sum Plus Plus // dp[i][j] = max(dp[i][j-1], dp[i-1][t]) + num[j] // pre[j-1] 存放dp[i-1] ...

  5. 专题:DP杂题1

    A POJ 1018 Communication System B POJ 1050 To the Max C POJ 1083 Moving Tables D POJ 1125 Stockbroke ...

  6. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  7. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  8. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

  9. poj 动态规划的主题列表和总结

    此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...

随机推荐

  1. bzoj 2327 构图暴力判断+独立集个数

    首先我们可以处理出10^6以内的所有的勾股数,如果我们有2*i-1和2*j互质, 那么A=(2*i-1)*(2*i-1)+(2*i-1)*(2*j),B=2*j*j+(2*i-1)*(2*j)为互质 ...

  2. Leetcode#145 Binary Tree Postorder Traversal

    原题地址 递归写法谁都会,看看非递归写法. 对于二叉树的前序和中序遍历的非递归写法都很简单,只需要一个最普通的栈即可实现,唯独后续遍历有点麻烦,如果不借助额外变量没法记住究竟遍历了几个儿子.所以,最直 ...

  3. matrix_world_final_2011

    C  http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98613#problem/C 题意:输入16进制的n*m矩阵,其在二进制表示下有6种 ...

  4. 2014ACM/ICPC亚洲区广州站 北大命题

    http://acm.hdu.edu.cn/showproblem.php?pid=5131 现场赛第一个题,水题.题意:给水浒英雄排序,按照杀人数大到小,相同按照名字字典序小到大.输出.然后对每个查 ...

  5. 【bzoj1013】[JSOI2008]球形空间产生器sphere

    1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4530  Solved: 2364[Subm ...

  6. ios后台下载

    http://www.cocoachina.com/industry/20131106/7304.html

  7. 关于WSDL

    Message Operation 最核心的在于Operation 只要关心Operation就可以了,Operation只有Input, Output没有其他内容,是相对固定的.只要关心一下Inpu ...

  8. mysql date数据类型异常原因0000-00

    1.数据库字段: `dri_lic_first_time` date DEFAULT NULL COMMENT '驾驶证初次领证日期', 2.异常信息 org.springframework.dao. ...

  9. poj 1704

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7233   Accepted: 2173 D ...

  10. iOS打电话,发短信,发邮件,打开网址

    //调用自带mail [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzl ...