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 ...
随机推荐
- (转)linux实战考试题:批量创建用户和密码-看看你会么?
老男孩教育第五关实战考试题:批量创建10个用户stu01-stu10,并且设置随机8位密码,要求不能用shell的循环(例如:for,while等),只能用linux命令及管道实现. 方法1:[roo ...
- 不同ORM新的理解
对于ORM你怎么理解?你用过的ORM有什么区别?这是面试的时候基本上会问的问题. 问题很简单,本文不在阐述.本文主要讨论Dapper 和 EF Core First的区别. 从直观上来看两个都是ORM ...
- java 通用查询框架Querydsl 简介
Querydsl 是一个通用的查询框架,专注于通过JavaAPI构建类型安全的SQL查询说说Querydsl的优势吧: 1. Querydsl支持代码自动完成,因为才纯Java API编写查询,因此主 ...
- Oracle ERP Interface堵住--Request Running too long time,查找Request执行的Sql
Request Running too long time 堵住了INV Manager 导致INV Interface Pending 很多笔资料 Review 发现Request 实际执行SQL ...
- C#关键字:yield
yield是C#为了简化遍历操作实现的语法糖.在语句中使用 yield 关键字,表示在该关键字所在的方法.运算符或 get 访问器是迭代器.有两种形式: yield return <expres ...
- js中Object.defineProperty()和defineProperties()
在介绍js中Object.defineProperty()和defineProperties()之前,我们了解下js中对象两种属性的类型:数据属性和访问器属性. 数据属性 数据属性包含一个数据的位置, ...
- 初学Android,创建,启动,停止Service(五十八)
Service跟Windows系统里的服务概念差不多,都在后台执行,它跟Activity的最大区别就是,它是无界面的 开发Service与开发Activity的步骤类似 1.定义一个继承Service ...
- uvm_reg_fifo——寄存器模型(十五)
当我们对寄存器register, 存储器memory, 都进行了建模,是时候对FIFO进行建模了 uvm_reg_fifo毫无旁贷底承担起了这个责任,包括:set, get, update, read ...
- dstat工具使用介绍
一.dstat工具多功能系统资源统计生成工具.获取信息类似top.free.iostat.vmstat等多个工具的合集,所以也称为vmstat.iostat.ifstat等工具替代品,其结果可以存储成 ...
- volatile引发的一系列血案
最早读<深入理解java虚拟机>对于volatile部分就没有读明白,最近重新拿来研究并记录一些理解 理解volatile前需要把以下这些概念或内容理解: 1.JMM内存模型 2.并发编程 ...