Chocolate
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 8245   Accepted: 2186   Special Judge

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

Source

题意:C种颜色的巧克力在桶中,从里面依次拿出n个巧克力,颜色同样的吃掉,求最后剩下m个巧克力的概率

当n>1000 时候,考虑奇偶性取1000或1001就可以,由于非常大的时候概率会趋于稳定,至于奇数时取1001 偶数

时取1000有些不解

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#define N 1010
using namespace std;
double dp[N][110];
int main()
{
int c,n,m;
while(scanf("%d",&c)!=EOF)
{
if(c==0)
{
break;
}
scanf("%d %d",&n,&m);
if(m>c||m>n||(n-m)%2)
{
printf("0.000\n");
continue;
}
if(n>1000)
{
n = 1000+n%2;
}
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
dp[1][1] = 1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=i&&j<=c;j++)
{
if(j-1>=0)
{
dp[i][j] = dp[i-1][j-1]*(double)(c-j+1)/(double)c;
}
dp[i][j] += dp[i-1][j+1]*(double)(j+1)/(double)c;
}
}
printf("%.3lf\n",dp[n][m]);
}
return 0;
}

POJ 1322 Chocolate的更多相关文章

  1. POJ 1322 Chocolate(母函数)

    题目链接:http://poj.org/problem?id=1322 题意: 思路: double C[N][N]; void init() { C[0][0]=1; int i,j; for(i= ...

  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. Use GraceNote SDK in iOS(一)通过序列化GDO查询专辑封面

    于Use MusicBrainz in iOS之后,因为MusicBrainz找出专辑封面,它只能转移到其他网站提供的音乐信息搜索服务,领导给出GraceNote.(有压力.. .) 需求类似:通过一 ...

  2. C#去除byte数组头尾杂质(即不需要的数据)

    代码如下: /// <summary> /// 去除byte数组头尾杂质(即不需要的数据) /// </summary> /// <param name="ar ...

  3. 关于ubuntu16.04给firefox安装flash的补充

    这两天把自己的老笔记本安装了ubuntu的16.04版本,关于给firefox安装flash player的方法,网上有很多,但不知道是版本还是其它原因,他们文章都出现目录错误的问题,我个人由于是ub ...

  4. datagrid的基本操作-增删改

    1 ---恢复内容开始--- <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  5. 掌众android面试题

    1,android动画分类? http://www.cnblogs.com/angeldevil/archive/2011/12/02/2271096.html 2,android service启动 ...

  6. ORA-01810格式代码出现两次 的解决方案

    今早做一个查询页面时,需要查询两个时间区间的跨度,使用TO_DATE函数,一开始写成了Sql代码 TO_DATE('2014-08-04 00:00:00','YYYY-MM-DD HH:mm:ss' ...

  7. 万事开头难,用HTML写的第一个界面,收获颇多

        很开心跟了叶老师学习和做项目,基础不好,前期他会帮你安排好学习路线和计划.前期没有项目做,叶老师先让我先学习jQuery,给我推荐了一些网站,叫我一边学习,一边写博客.其实很早就有想写博客的想 ...

  8. UML类图常见的几种关系

    关系:泛化(Generalization),实现(Realization),关联(Association),聚合(Aggregation),组合(Composition),依赖(Dependency) ...

  9. (原)torch使用caffe时,提示CUDNN_STATUS_EXECUTION_FAILED

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6230227.html 提前说明:此文不能真正解决该问题,具体原因我也不知道... 以前使用某台电脑A上 ...

  10. XP 安装

    提供一下裝系統的詳細步驟,盡量詳細到每一步都有,希望能對樓主有所幫助,不盡之處還請樓主不吝指出!謝謝 装XP的步骤如下: 开机时,按del键, 进入bios界面,一般选左侧第二项,(Advanced ...