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. [React Testing] Intro to Shallow Rendering

    In this lesson, we walk through how to use one of React's Test Utilities (from thereact-addons-test- ...

  2. I/O输出端口照明LED

    方案特点:I/O输出端口照明LED.而区间0.2秒闪烁!(非计时器延迟) (P1.0销被连接到LED) LED EQU P1.0 ;宏定义 ORG 0000H LJMP MAIN ORG 0200H ...

  3. VMware Virtual Machine安装报错解决1

    安装完VMware virtual machine 后,再进行 "create a new virtual machine"最后点击"Finish"时,报如下错 ...

  4. oracle 按某个字段查询重复数据

    /* 手机号为重复的会员,获取其最大会员id,对应的会员信息 */ SELECT * FROM MEMBER a WHERE a.member_id IN ( SELECT MAX(member_id ...

  5. 路由器密码破解工具 Hydra 7.5

    之前只在 Browser 中保存了路由管理密码,无奈升级时管理的密码丢失了,又不想重新设置,所以尝试破解登录密码. 使用破解工具 Hydra 7.5. # hydra -l username -x : ...

  6. oracle 查询前一小时、一天、一个月、一年的数据

    查询一小时 select concat(to_char(sysdate,'yyyy-mm-dd ')||(to_char(sysdate,'hh24')-1),':00:00') start_time ...

  7. out返回值的用法与用途

    static void Main(string[] arr) { Console.WriteLine("请输入用户名"); string uname = Console.ReadL ...

  8. zoj 3755

    状态压缩dp 扫雷 n×M格子奇数行有雷,给出偶数行的数字,求最少有多少个雷. 刚开始觉得状压状态不知道怎么办,因为每行能影响的范围太广,后来展昭说横着来,然后几分钟就a了. 这件事请告诉我们看问题要 ...

  9. SuperMap

    SuperMap iClient for JavaScript 新手入门 地理信息系统(英语:Geographic Information System,缩写:GIS)是一门综合性学科,结合地理学与地 ...

  10. soapUI通过groovy脚本设置超时时间

    import com.eviware.soapui.SoapUI import com.eviware.soapui.settings.HttpSettings import com.eviware. ...