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. node.js安装Oracledb指导文档

    https://community.oracle.com/docs/DOC-931127

  2. AD17笔记

    1 铺铜修改后自动重铺设置:在最右下角

  3. Oracle更新表字段时内容中含有特殊字符&的解决方法

    今天在做 Oracle表字段更新时出现了特殊字符&,导致无法更新. 这个问题是第二次碰到了,所以在此记录下,以备后用. 举例: update t set col1='A&B' wher ...

  4. Java 多线程概念

    1.为什么要使用多线程: 更多的处理器核心. 更快的响应时间. 更好的变成模型. 2.线程的优先级: 现代操作系统基本采用时分的形式调度运行的线程,操作系统会分出一个个的时间片,线程会分配到若干时间片 ...

  5. MyBatis学习总结(二)---实例

    为了对MyBatis有个初步了解,现做一个简单的增.删.改.查实例.了解涉及的文件与相关作用. MySql创建friends表,以下是表的sql语句 DROP TABLE IF EXISTS `fri ...

  6. JAVA分包下项目部分代码存储

    一.注册时姓名去重和符合汉字格式: // 新用户申请加入 public void NewHuman() { System.out.println("========新会员申请加入页面==== ...

  7. Android笔记--View绘制流程源码分析(二)

    Android笔记--View绘制流程源码分析二 通过上一篇View绘制流程源码分析一可以知晓整个绘制流程之前,在activity启动过程中: Window的建立(activit.attach生成), ...

  8. django之分页插件

    from django.utils.safestring import mark_safe class Page: def __init__(self, current_page, data_coun ...

  9. equals()方法详解

    Java语言中equals()方法的使用可以说比较的频繁,但是如果轻视equals()方法,一些意想不到的错误就会产生.哈哈,说的有点严重了~ 先谈谈equals()方法的出身.equals()方法在 ...

  10. hadoop的shell总结

    ls命令(文件内容) 列出系统跟目录下的目录和文件 Hadoop fs -ls / 列出文件系统所有的目录和文件 Hadoop fs -ls -R / cat命令(列出文档内容) Hadoop fs ...