POJ 1322 Chocolate
| Time Limit: 2000MS | Memory Limit: 65536K | |||
| Total Submissions: 8245 | Accepted: 2186 | Special Judge | ||
Description
"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
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
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的更多相关文章
- POJ 1322 Chocolate(母函数)
题目链接:http://poj.org/problem?id=1322 题意: 思路: double C[N][N]; void init() { C[0][0]=1; int i,j; for(i= ...
- poj 1322 Chocolate (概率dp)
///有c种不同颜色的巧克力.一个个的取.当发现有同样的颜色的就吃掉.去了n个后.到最后还剩m个的概率 ///dp[i][j]表示取了i个还剩j个的概率 ///当m+n为奇时,概率为0 # inclu ...
- Solution -「ACM-ICPC BJ 2002」「POJ 1322」Chocolate
\(\mathcal{Description}\) Link. \(c\) 种口味的的巧克力,每种个数无限.每次取出一个,取 \(n\) 次,求恰有 \(m\) 个口味出现奇数次的概率. \( ...
- 经典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] ...
- 专题:DP杂题1
A POJ 1018 Communication System B POJ 1050 To the Max C POJ 1083 Moving Tables D POJ 1125 Stockbroke ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
- poj 动态规划的主题列表和总结
此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...
随机推荐
- 在Debian Wheezy 7.3.0上编译安装3.12.14内核
最近需要对Linux的一个内核模块进行调整实验,故决定先在虚拟机中完成编译调试工作,最后再在真实的系统上进行测试.为了防止遗忘,把过程记录于此. 1. 准备系统环境 首先从官网下载最新版的Virtua ...
- centos7启动时出现“无法应用原保存的显示器配置”
设置了分辨率后,登录提示“出现无法应用原保存的显示器配置”. 解决办法: 打开终端,输入 rm ~/.config/monitors.xml 然后重新登录, 问题解决.
- 最全C语言笔记回顾
- (五)JS学习笔记 - Sizzle选择器
Sizzle词法解析 sizzle对于分组过滤处理都用正则,其中都有一个特点,就是都是元字符^开头,限制匹配的初始,所以tokenize也是从左边开始一层一层的剥离. •可能会应用到正则如下: // ...
- 贪心 CF 332 C 好题 赞
题目链接: http://codeforces.com/problemset/problem/332/C 题目意思: 有n个命令,要通过p个,某主席要在通过的p个中选择k个接受. 每个任务有两个值ai ...
- iOS开发:自定义tableViewCell处理的问题
还在适配iOS6,索性下一个版本不适配了~~~~~ 问题: *** Assertion failure in -[ PCDiaryDetailReplyCell layoutSublayersOfLa ...
- Lintcode--010(最长上升子序列)
给定一个整数序列,找到最长上升子序列(LIS),返回LIS的长度.LIS(longestIncreasingSubsequence) 说明: 最长上升子序列的定义: 最长上升子序列问题是在一个无序的给 ...
- 关于nginx架构探究(1)
nginx的架构主要是有一个主监控进程:master;三个工作进程:worker:还有Cache的两个进程.back-end-server是后端服务器,主要是处理后台逻辑.nginx作为代理服务器需要 ...
- 枚举类:用enum关键字来定义一个枚举类
1)枚举类的两种定义方法 1>通过构造器 public enum Grade{ A("A", "90-100"),B("B",&quo ...
- 智能卡安全机制比较系列(一)CardOS
自从智能卡开始进入人们的日常生活之后,大家对于智能卡的安全性普遍看好,但是不同公司的智能卡在安全机制的实现方面也存在很多的差异.对于智能卡应用开发和智能卡COS设计人员来说,如果能够更多地了解不同公司 ...