Card

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 191    Accepted Submission(s): 52
Special Judge

Problem Description
There are x cards on the desk, they are numbered from 1 to x. The score of the card which is numbered i(1<=i<=x) is i. Every round BieBie picks one card out of the x cards,then puts it back. He does the same operation for b rounds. Assume that the score of the j-th card he picks is Sj . You are expected to calculate the expectation of the sum of the different score he picks.
 
Input
Multi test cases,the first line of the input is a number T which indicates the number of test cases. 
In the next T lines, every line contain x,b separated by exactly one space.

[Technique specification]
All numbers are integers.
1<=T<=500000
1<=x<=100000
1<=b<=5

 
Output
Each case occupies one line. The output format is Case #id: ans, here id is the data number which starts from 1,ans is the expectation, accurate to 3 decimal places.
See the sample for more details.
 
Sample Input
2
2 3
3 3
 
Sample Output
Case #1: 2.625
Case #2: 4.222

Hint

For the first case, all possible combinations BieBie can pick are (1, 1, 1),(1,1,2),(1,2,1),(1,2,2),(2,1,1),(2,1,2),(2,2,1),(2,2,2)
For (1,1,1),there is only one kind number i.e. 1, so the sum of different score is 1.
However, for (1,2,1), there are two kind numbers i.e. 1 and 2, so the sum of different score is 1+2=3.
So the sums of different score to corresponding combination are 1,3,3,3,3,3,3,2
So the expectation is (1+3+3+3+3+3+3+2)/8=2.625

 
 
我的做法是把它想象成一棵 m 层的 x 叉树(底层有 x^b 个叶子结点), 然后计算每个数字(1~x )要加的次数。
对于( i = 1 ~  x ) ..  
在第1层就要加 x^( m-1 ) 次 。
第2层就要加 x^(m-2) *(x-1) 次 。
....
第 i 层就要加 x^( m - i ) * (x-1)^( i - 1 )。
....
第m层就要加 x^(0) *(x-1)^(m-1) 次。
 
 以 i = 1 为例 ,如下图:
 
那么每个数加的次数就是  x^i * ( x - 1 )^( m - i - 1 ) 次 [ 0 <= i < m ]。
总共加的和 sum = sigma(j) * x^i * ( x - 1 )^( m - i - 1 ) 次 [ 1<=j <= x , 0 <= i < m ]。
sigma(j) [1<=j <= x ] = (1+x)*x/2。
那么 sum = (1+x) * x / 2 * x^i * ( x - 1 )^( m - i - 1 ) , [ 0 <= i < m ] 。 
那么期望 Ex = sum / ( x ^ n ) 。
 
 
官方题解是给出普通用概率方法求 :
设Xi代表分数为i的牌在b次操作中是否被选到,Xi=1为选到,Xi=0为未选到
那么期望EX=1*X1+2*X2+3*X3+…+x*Xx
Xi在b次中被选到的概率是1-(1-1/x)^b
那么E(Xi)= 1-(1-1/x)^b
那么EX=1*E(X1)+2*E(X2)+3*E(X3)+…+x*E(Xx)=(1+x)*x/2*(1-(1-1/x)^b)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1
typedef long long LL;
typedef pair<int,int>pii;
#define X first
#define Y second
const int oo = 1e9+;
const double PI = acos(-1.0);
const double eps = 1e- ;
const int N = ;
double n ;int m ;
void Run() {
scanf("%lf%d",&n,&m);
double avg = ( 1.0 + n ) * n / 2.0 * pow( 1.0 / n , (double) m ) , res = ;
for( int i = ; i < m ; ++i ) {
res += avg * pow( n - 1.0 , (double)i )*pow( (double)n, m-i-1.0 );
}
printf("%.3lf\n",res);
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
int _ , cas = ; scanf("%d",&_);
while( _-- ){
printf("Case #%d: ",cas++); Run();
}
}
 

HDU 5159 Card( 计数 期望 )的更多相关文章

  1. hdu 5159 Card (期望)

    Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...

  2. HDU 5159 Card (概率求期望)

    B - Card Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  3. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

  4. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

  5. HDU 5159 Card

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b, ...

  6. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  7. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  8. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. Card Collector(期望+min-max容斥)

    Card Collector(期望+min-max容斥) Card Collector woc居然在毫不知情的情况下写出一个min-max容斥 题意 买一包方便面有几率附赠一张卡,有\(n\)种卡,每 ...

随机推荐

  1. redhat6.5单用户重置root密码

    (1),按 “e” 键进入该界面,继续按 “e” 键进入下一个界面. (2).上下键选中第二个kernel选项,继续按 “e” 键进行编辑. (3).在新的界面里面加一个空格,再输入“1”:或者输入“ ...

  2. cgi+lighttpd上传大文件失败解决办法

    问题: - 前端页面点击上传按钮,不超过30M的小文件顺利上传到板子指定位置,上传60Md的更新包,出错,http状态码413——请求实体过大 环境: - web服务器——lighttpd1.4.30 ...

  3. JS面向对象——组合使用构造函数模型与原型模型

    该模型为创建自定义类型最常用的方式. <!DOCTYPE html> <html> <head> <title>组合使用构造函数模型和原型模型</ ...

  4. Git配置全局账号密码避免每次拉取、提交输入账号密码

    前言 在大家使用github的过程中,一定会碰到这样一种情况,就是每次要push 和pull时总是要输入github的账号和密码,这样不仅浪费了大量的时间且降低了工作效率.在此背景下,本文在网上找了两 ...

  5. 246-基于TI DSP TMS320C6678、Altera FPGA的CPCI处理卡

    基于TI DSP TMS320C6678.Altera FPGA的CPCI处理卡 1.板卡概述  本板卡由我公司自主研发,基于CPCI架构,符合CPCI2.0标准,采用两片TI DSP TMS320C ...

  6. K8S命令大总结

    一.k8s-kubectl命令大全 Kubectl命令行管理对象类型 命令 描述 基础命令 create 通过文件名或标准输入创建资源. expose 将一个资源公开为一个新的Kubernetes服务 ...

  7. go语言从例子开始之Example33.工作池

    在这个例子中,我们将看到如何使用 Go 协程和通道实现一个工作池 . Example: package main import "fmt" import "time&qu ...

  8. "Unable to locate package lrzsz"的解决办法

    某天安装一些常用软件,比如lrzsz的时候出错了 $ sudo apt-get install lrzsz Reading package lists... Done Building depende ...

  9. Android】Retrofit网络请求参数注解,@Path、@Query、@QueryMap...(转)

    对Retrofit已经使用了一点时间了,是时候归纳一下各种网络请求的service了. 下面分为GET.POST.DELETE还有PUT的请求,说明@Path.@Query.@QueryMap.@Bo ...

  10. 异常关机,同时出现:Last_IO_Errno: 1236,Last_SQL_Errno: 1594

    一主两从的结构,由于异常关机,导致两个从库都出现如下问题: mysql> show slave status \G;*************************** 1. row **** ...