Alice and Bob are playing a simple game. They line up a row of n identical coins, all with the heads facing down onto the table and the tails upward.

For exactly mm times they select any k of the coins and toss them into the air, replacing each of them either heads-up or heads-down with the same possibility. Their purpose is to gain as many coins heads-up as they can.

Input

The input has several test cases and the first line contains the integer t(1≤t≤1000) which is the total number of cases.

For each case, a line contains three space-separated integers n, m1≤n,m≤100) and k (1≤k≤n).

Output

For each test case, output the expected number of coins heads-up which you could have at the end under the optimal strategy, as a real number with the precision of 33 digits.

样例输入

6
2 1 1
2 3 1
5 4 3
6 2 3
6 100 1
6 100 2

样例输出

0.500
1.250
3.479
3.000
5.500
5.000

题目来源

ACM-ICPC 2017 Asia Urumqi

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
int t,n,m,k;
const int N=;
double dp[N][N];
double c[N][N];//ll也会爆,一定要写成double
double p[N];
double ans;
void C()
{
c[][]=;
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
{
if(j==||j==i) c[i][j]=;
else {
c[i][j]=c[i-][j-]+c[i-][j];
}
}
}
p[]=;
for(int i=;i<=;i++) p[i]=p[i-]/;
}
int main()
{
scanf("%d",&t);
C();
/*
for(int i=1;i<=100;i++)
{ printf("%dllll\n",i);
for(int j=0;j<=i;j++)
{
printf("%d%c",c[i][j],j==i?'\n':' ');
}
//c[33][j]就爆int 了。
}
*/
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
memset(dp,,sizeof(dp));
//dp[i][j]: i次操作后,正面朝上的面数为j的概率
dp[][]=;//初始都是反面
for(int i=;i<m;i++)
{
for(int j=;j<=n;j++)
{
for(int l=;l<=k;l++)//取得k个里面l个正面朝上。
{ //反面的个数大于k,直接从反面的里面取k个
if((n-j)>=k) dp[i+][j+l]+=dp[i][j]*c[k][l]*p[k];//取出的K个硬币每个的结果概率都是1/2(正/反)
//反面的个数小于k,只能再从已经是正面的里面再取出k-(n-j)个。
else dp[i+][j-(k-(n-j))+l]+=dp[i][j]*c[k][l]*p[k];
}
}
}
ans=;
for(int i=;i<=n;i++)ans+=i*dp[m][i];//期望,别忘了*i
printf("%.3f\n",ans);
}
return ;
}

ACM-ICPC 2017 Asia Urumqi A. Coins的更多相关文章

  1. ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】

    题目链接:https://www.jisuanke.com/contest/2870?view=challenges 题目大意:给出n个都正面朝下的硬币,操作m次,每次都选取k枚硬币抛到空中,求操作m ...

  2. ACM-ICPC 2017 Asia Urumqi:A. Coins(DP) 组合数学

    Alice and Bob are playing a simple game. They line up a row of nn identical coins, all with the head ...

  3. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  4. ACM ICPC 2017 Warmup Contest 9 L

    L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...

  5. ACM-ICPC 2017 Asia Urumqi G. The Mountain

    All as we know, a mountain is a large landform that stretches above the surrounding land in a limite ...

  6. 2017 ICPC Asia Urumqi A.coins (概率DP + 期望)

    题目链接:Coins Description Alice and Bob are playing a simple game. They line up a row of nn identical c ...

  7. ACM-ICPC 2017 Asia Urumqi:A. Coins(DP)

    挺不错的概率DP,看似基础,实则很考验扎实的功底 这题很明显是个DP,为什么???找规律或者算组合数这种概率,N不可能给的这么友善... 因为DP一般都要在支持N^2操作嘛. 稍微理解一下,这DP[i ...

  8. ACM-ICPC 2017 Asia Urumqi(第八场)

    A. Coins Alice and Bob are playing a simple game. They line up a row of nnn identical coins, all wit ...

  9. ACM ICPC 2017 Warmup Contest 1 D

    Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...

随机推荐

  1. 《深入理解java虚拟机》笔记(7)JVM调优(分代垃圾收集器)

    以下配置主要针对分代垃圾回收算法而言. 一.堆大小设置 年轻代的设置很关键 JVM中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内存限制:系统的可用 ...

  2. TDH-search汇报理解

    题目:海量数据查询开头:1.自我介绍:2.题目切入: 什么是海量数据查询?(海量数据,快速,符合要求) 几个常用场景(搜索引擎,百度:话单查询:影像平台,高铁)3.展示目录:架构,案例,平台规划 4. ...

  3. Golang 入门系列(十三)用Beego开发web应用

    接着之前的内容,前面已经讲过很多Golang的基础语法,mysql的使用,redis的使用,也讲了orm框架,如何创建一个webapi 服务等等,感兴趣的可以看看以前的文章,https://www.c ...

  4. 《java学习二》并发编程

    多线程创建方式 1.继承thread类,重写run方法 CreateThread createThread = new CreateThread();     ------createThread  ...

  5. ios 绘制虚线 CGContextSetLineDash的使用

    画虚线需要用到函数: CGContextSetLineDash 此函数需要四个参数: context – 这个不用多说 phase - 稍后再说 lengths – 指明虚线是如何交替绘制,具体看例子 ...

  6. 总结一下WindowListener的用法

    记录一下便于自己查看 1.WindowListener java.awt.event 接口 WindowListener public interface WindowListener extends ...

  7. Spring 设计原则

    Spring 框架有四大原则(Spring所有的功能和设计和实现都基于四大原则): 1. 使用POJO进行轻量级和最小侵入式开发. 2. 通过依赖注入和基本接口编程实现松耦合. 3. 通过AOP和基于 ...

  8. (2017.10.16) javascript 数据类型转换与操作

    javascript 有 5 种基本数据类型:undefined.null.Boolean.String.Number,还有1 种较复杂的数据类型 Object:各种类型之间可以相互转换,其中有些有趣 ...

  9. Android RecyclerView使用GridLayoutManager导致间隙变大的问题

    我用recyclerView的时候设置LayoutManager为Grid,添加decoration为Grid,作为二级列表时,多次点击一级列表来跳转的时候,两张图之间的间隙在逐渐变大,后来发现是因为 ...

  10. [选择排序] 时间复杂度O(n^2)

    思路:从未排序的序列中,找到最小的元素,放到序列的起始位置, 再从剩下没排序的里面,找到最小的,放到已经排序的末尾. 原地操作几乎是选择排序的唯一优点,当空间复杂度要求较高时,可以考虑选择排序:实际适 ...