时间复杂度很大。dp[i][j]表示第i轮 j这种状态的概率。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; double dp[][];
int T;
int M;
int X;
double P; void work()
{
memset(dp,,sizeof dp);
dp[][<<M]=1.00;
for(int r=; r<=M; r++)
{
for(int j=; j<=(<<M); j++)
{
double ans=;
for(int k=;; k++)
{
if(j+k>(<<M)||j-k<) break;
ans=max(ans,P*dp[r-][j+k]+(-P)*dp[r-][j-k]);
}
dp[r][j]=ans;
}
}
} int main()
{
//freopen("C-large-practice.in","r",stdin);
// freopen("C-large-practice.out","w",stdout); scanf("%d",&T);
for(int Case=; Case<=T; Case++)
{
scanf("%d%lf%d",&M,&P,&X);
work();
long long XX=(long long)X;
int d=(<<M);
long long dd=(long long)d;
long long RR=XX*dd/(long long);
int R=int(RR);
printf("Case #%d: %6lf\n",Case,dp[M][R]);
}
return ;
}

GCJ 2008 APAC local onsites C Millionaire的更多相关文章

  1. 2008 APAC local onsites C Millionaire (动态规划,离散化思想)

    Problem You have been invited to the popular TV show "Would you like to be a millionaire?" ...

  2. GCJ2008 APAC local onsites C Millionaire

    自己Blog的第一篇文章,嗯... 接触这道题,是从<挑战程序设计竞赛>这本书看来的,其实头一遍读题解,并没有懂.当然现在已经理解了,想想当初可能是因为考虑两轮的那张概率图的问题.于是决定 ...

  3. Code Jam 2008 APAC local onsites Problem C. Millionaire —— 概率DP

    题意: 你有X元钱,进行M轮赌博游戏.每一轮可以将所持的任意一部分钱作为赌注(赌注为0元表示这一轮不押),赌注可以是小数的,不是一定要整数.每一轮 赢的概率为P,赢了赌注翻倍,输了赌注就没了.如果你最 ...

  4. GCJ 2008 Round 1A Minimum Scalar Product

    https://code.google.com/codejam/contest/32016/dashboard 题目大意: GCJ(google code jam)上的水题.下周二有比赛,来熟悉熟悉. ...

  5. GCJ 2008 Round 1A Minimum Scalar Product( 水 )

    链接:传送门 题意:给两个向量 v1 = { x1 , x2 , x3 , x4 .... } , v2 = { y1 , y2 , y3 , y4 ...... } 允许任意交换 v1 和 v2 各 ...

  6. ProgrammingContestChallengeBook

    POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...

  7. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  8. 在WPF程序中打开网页:使用代理服务器并可进行JS交互

    本项目环境:使用VS2010(C#)编写的WPF程序,通过CefSharp在程序的窗体中打开网页.需要能够实现网页后台JS代码中调用的方法,从网页接收数据,并能返回数据给网页.运行程序的电脑不允许上网 ...

  9. 【转】WPF TextBox和PasswordBox加水印

    Textbox加水印 Textbox加水印,需要一个VisualBrush和触发器验证Text是否为空,在空的时候设置背景的Brush就可以实现水印效果. <TextBox Name=" ...

随机推荐

  1. Newly Setting up a CentOS-7 system

    yum install -y epel-release glibc.i686 libtools vim clang git autoconf automake w3m glibc screen the ...

  2. mysql 字段的类型有哪些

    int型包括(tinyint, smallint, mediumint, int, bigint) tinyint是1个字节表达范围就是2的8次方(-128-128) 或者(0-255) 很多人不明白 ...

  3. Windows API 之 CreateFile

    Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: file, file ...

  4. editplus 正则删换行

    editplus regular expression  ctrl+h 1.替换开始是空行 ^[\t ]*\n 2.替换换行 \n 3.替换包含某字符 .*@126.* excel去重复(或者保留一个 ...

  5. YII2 过滤器 filters

    使用过滤器 过滤器本质上是一类特殊的 行为,所以使用过滤器和 使用 行为一样. 可以在控制器类中覆盖它的 yii\base\Controller::behaviors() 方法来申明过滤器, 如下所示 ...

  6. 为什么MVC不是一种设计模式? ---比较Backbone和Ext4.x在MVC实现上的差异

    为什么MVC不是一种设计模式? ---比较Backbone和Ext4.x在MVC实现上的差异 大漠穷秋 前言 圣人云:不想做妈咪的小姐不是好码农. 每一个码农的心中都有一个终极理想,那就是有一天不用再 ...

  7. deibian不能加vpn

    http://www.cyberciti.biz/faq/deiban-ubuntu-linux-networkmanager-pptp-cisco-vpn-tab-disabled/ 经常搜goog ...

  8. ide编码害死人

    1.从网上复制代码的时候不要直接复制代码到ide中(MyEclipse,Eclipse)中这样在一般的情况下就没问题,但是在有编码规则的时候需要特别的小心,建议先复制到本地的txt文件中,然后在复制到 ...

  9. hadoop Yarn运行机制

  10. 方便android开发网站:

    可以通过输入包名或者Google Play地址消灾google市场的应用 http://apps.evozi.com/apk-downloader/ 16进制转常用的10进制 http://www.b ...