POJ 1322 Chocolate(母函数)
题目链接: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(母函数)的更多相关文章
- POJ 1322 Chocolate
Chocolate Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8245 Accepted: 2186 Speci ...
- 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, ...
随机推荐
- JS 学习笔记--2--变量的声明
1.ECMAScript 中规定所有的关键字.保留字.函数名.函数名.操作符等都是区分大小写的. 2.标识符:指变量.函数.属性的名字:标识符组成:以字母.下划线.$ 开头,其他字母可以含有数字, ...
- 使用fwrite()函数和fprintf()函数输出数据到文件时的区别
使用书上的一个课后题为例 有5个学生,每个学生有3门课的成绩,从键盘输入学生数据(包括学号,姓名,3们课程成绩),计算出每个学生的平均成绩,将原有数据和计算出的平均分数存放在磁盘文件“stud”中. ...
- HDOJ 1709 The Balance(母函数)
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- JS数据类型的理解(猜测)
Js 数据类型 对于这个主题,首先来看几个问题,如果你对这几个问题很清楚的话,那就请直接跳过吧,不用接着往下看了,如果不清楚,建议你还是看看. 1)如果判断函数?function 和object的联系 ...
- 国内Jquery CDN
新浪CDN: <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js">< ...
- ZOJ3238 Water Ring(计算几何)
题意:给你一个圆形和很多个矩形,然后要你求圆形的圆周有多少被矩形覆盖. 思路:比赛的时候是有思路的了,不过一直在调别的题,最后剩下30分钟肯定来不及敲.想法是这样的,要是我们可以求出每个矩形覆盖了圆周 ...
- call by reference and copy/restore
转自:http://stackoverflow.com/questions/8848402/whats-the-difference-between-call-by-reference-and-cop ...
- uva 11090
I I U P C 2 0 0 6 Problem G: Going in Cycle!! Input: standard input Output: standard output You are ...
- POJ 2482 Stars in Your Window (线段树+扫描线+区间最值,思路太妙了)
该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/ts ...
- Spring mvc json null
http://blog.csdn.net/zdsdiablo/article/details/9429263