ACM-ICPC 2017 Asia Urumqi A. Coins
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
题目来源
#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的更多相关文章
- ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】
题目链接:https://www.jisuanke.com/contest/2870?view=challenges 题目大意:给出n个都正面朝下的硬币,操作m次,每次都选取k枚硬币抛到空中,求操作m ...
- 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 ...
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- 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 ...
- 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 ...
- 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 ...
- ACM-ICPC 2017 Asia Urumqi:A. Coins(DP)
挺不错的概率DP,看似基础,实则很考验扎实的功底 这题很明显是个DP,为什么???找规律或者算组合数这种概率,N不可能给的这么友善... 因为DP一般都要在支持N^2操作嘛. 稍微理解一下,这DP[i ...
- 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 ...
- ACM ICPC 2017 Warmup Contest 1 D
Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...
随机推荐
- 如何给数组用fill函数和memset函数给数组赋初值
fill是按照单元来赋值的,所以可以填充一个区间的任意值 #include<iostream> #include<stdio.h> #include<string.h&g ...
- 项目打包发布到tomcat中,中文出现乱码
先吐槽一下,花了我3个小时,心累 本地运行正常,发布时maven插件里要加utf-8编码 https://blog.csdn.net/testcs_dn/article/details/4558379 ...
- 在MVC中使用dotless后台动态解析LESSCSS的学习笔记
通过学习LessCSS,我们知道,Less是需要通过编译才能生成 .css 文件,主要使用三种方式进行编译: 1)使用第三方编译工具,在项目发布前编译好放在项目中. 2)在浏览器端解析执行,需要引用 ...
- C#、VSTO讀取Excel類
之前寫的類存在Excel進程不能結束的Bug,重寫ExcelReader類,類實例清理時Excel進程自動結束. class ExcelReader { // Excel Object public ...
- JAVA分包下项目部分代码存储
一.注册时姓名去重和符合汉字格式: // 新用户申请加入 public void NewHuman() { System.out.println("========新会员申请加入页面==== ...
- JavaWeb项目开发中eclipse缓存问题
学习Java快2年了 有时候改完代码启动tomcat测试时,新代码不生效,这可能就是缓存问题. 所以平时就用以下几个方法解决,如果还是解决不了,就找老师吧! 1.清理项目 2.移除项目,清理tomca ...
- JS根据选择的日期计算年龄
本例中用的是easyUI的datebox $('#cal_birthday').datebox({ onSelect: function(date){ //根据选则的日期计算年龄 //alert(da ...
- FAST FW150R软件版本升级解决一些网页无法加载问题
家里用的移动宽带,通过无线路由器无线上网.上taobao.天猫都很快,但是一上京东.苏宁易购界面加载很慢,界面无法显示,怀疑是无线路由问题,然后直接通过网线相连接,发现问题消失,决定对无线路由软件版本 ...
- SlickEdit 18.0 版本发布 同时更新破解文件
18.0版本没有太大的惊喜 多了如下功能 Multiple Document Group Interface Repository Log Browser History Diff Support f ...
- ABAP Development Tools的语法高亮实现原理
ABAP Development Tools的前端是Java,根本识别不了ABAP.那么在ADT里的ABAP语法高亮是如何实现的? 第一次打开一个report时,显示在ADT里的代码是没有任何语法高亮 ...