Description

In 2100, ACM chocolate will be one of the favorite foods in the world.

"Green, orange, brown, red...", colorful sugar-coated shell maybe is the most attractive feature of ACM chocolate. How many colors have you ever seen? Nowadays, it's said that the ACM chooses from a palette of twenty-four colors to paint their delicious candy bits.

One day, Sandy played a game on a big package of ACM chocolates which contains five colors (green, orange, brown, red and yellow). Each time he took one chocolate from the package and placed it on the table. If there were two chocolates of the same color on the table, he ate both of them. He found a quite interesting thing that in most of the time there were always 2 or 3 chocolates on the table.

Now, here comes the problem, if there are C colors of ACM chocolates in the package (colors are distributed evenly), after N chocolates are taken from the package, what's the probability that there is exactly M chocolates on the table? Would you please write a program to figure it out?

Input

The input file for this problem contains several test cases, one per line.

For each case, there are three non-negative integers: C (C <= 100), N and M (N, M <= 1000000).

The input is terminated by a line containing a single zero.

Output

The output should be one real number per line, shows the probability for each case, round to three decimal places.

Sample Input

5 100 2

0

Sample Output

0.625 

【题意】给出c,n,m代表c种颜色的糖,从袋子里拿出n颗,放在桌子上,如果已经相同颜色,就把两颗都吃掉,问最后桌子剩m颗的概率

【思路】dp,dp[i][j]=dp[i-1][j-1]*(c-j+1)/c+dp[i-1][j+1]*(j+1)/c;

剪枝,m不可能大于n和c,并且n和m同奇同偶;

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
double dp[][];
int c,n,m;
while(cin>>c,c)
{
scanf("%d%d",&n,&m);
if(m>c||m>n||(n+m)&)
{
printf("0.000\n");
continue;
}
if(n>)//n很大时,误差可忽略不计
n=+(n&);
memset(dp,,sizeof(dp));
dp[][]=;
for(int i=;i<=n;i++)
{
dp[i][]=dp[i-][]/c;
dp[i][c]=dp[i-][c-]/c;
for(int j=;j<c;j++)
{
dp[i][j]=dp[i-][j-]*(double)(c-j+)/c+dp[i-][j+]*(double)(j+)/c;
}
}
printf("%.3f\n",dp[n][m]);
}
return ;
}

Chocolate_DP的更多相关文章

随机推荐

  1. JDE客户端get时报错“ERROR:fetch from table F0101 failed”

    客户端开发时发现总报错误“ERROR:fetch from table F0101 failed” 原因是用户ID在地址名册中找不到地址号.修改用户地址号即可.如下图所示

  2. ASP.NET Web API路由规

    默认的规则 在ASP.NET MVC4中 global.asax.cs代码中并无注册默认路由规则的代码 代码如下: public class WebApiApplication : System.We ...

  3. 用jquery或js实现三个div自动循环轮播

    //3个div的统一class = 'div' var index =0; //3秒轮播一次 var timer = setInterval(function(){     index = (inde ...

  4. FZU 2032 Log函数问题 模拟小数加法

    题目链接:Log函数问题 2 / 49 Problem G FZU 2032 Log函数问题 不知道为什么...比赛时高精度难倒了一票人...成功搞出大新闻... 试了一下直接double相加超时,然 ...

  5. treap codevs 4543普通平衡树

    #include<cstdio>#include<ctime>#include<cstdlib>struct shu{ int l,r,sum1,zhi,dui,s ...

  6. City Skyline

    题目大意:(poj 3044) 给出城市的正视图,所有的大楼都是矩形,给出正视图每个高度改变时的坐标,问最少有多少大楼.一共N个矩形,N<=50000 解题过程: 首先可以把问题转化一下:有N块 ...

  7. (DFS)zoj1008-Gnome Tetravex

    现在zoj暂时关了,实际上是在scuoj上做的. 题目地址 看起来题目比较复杂,实际上主要需要思维的是如何恰当的剪枝及合适的DFS角度. 问题等价于将n*n个可能相同的方块放到一个n*n的表中,使满足 ...

  8. Apache—DBUtils

    简介 commons-dbutils 是 Apache 组织提供的一个开源 JDBC工具类库,它是对JDBC的简单封装,学习成本极低,并且使用dbutils能极大简化jdbc编码的工作量,同时也不会影 ...

  9. win7 web开发遇到的问题-由于权限不足而无法读取配置文件,无法访问请求的页面

    错误一: HTTP Error 500.19 - Internal Server Error配置错误: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的 (ov ...

  10. xcode6 ios launchimage

    1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以及低版本的ios系 ...