Code Jam 2008 APAC local onsites Problem C. Millionaire —— 概率DP
题意:
你有X元钱,进行M轮赌博游戏。每一轮可以将所持的任意一部分钱作为赌注(赌注为0元表示这一轮不押),赌注可以是小数的,不是一定要整数。每一轮 赢的概率为P,赢了赌注翻倍,输了赌注就没了。如果你最后持有至少1000000元钱的话,就可以把钱全部带走。要求计算在采取最优策略时,获得至少 1000000元钱的概率。
数据范围:
0<=P<=1
1<=X<=1000000
1<=M<=15
int M , X ;
double P;
double dp[][( << ) + ];
void solve()
{
int n = << M;
double *pre = dp[] , *nxt = dp[];
memset(pre , , sizeof(double) * (n + ));
/// memset(pre , 0 , sizeof(pre)); 这样初始化是不行的,因为pre为一个double型的指针,不是整个数组。
pre[n] = 1.0;
for(int r = ; r < M; r++)///枚举第几轮
{
for(int i = ; i <= n ; i++)///枚举当前是哪种状态
{
int step = min(i , n - i);///如果step大于n / 2 , 等会儿转移的时候可能会超过n
double t = 0.0;
for(int j = ; j <= step ; j++)///枚举当前的所有可能走法
{
t = max(t , P * pre[i + j] + ( - P) * pre[i - j]);///求出期望的最大值
}
nxt[i] = t;
}
swap(pre , nxt);///交换两个数组的值进行滚动
}
int i = (LL)X * n / ;///找到X对应的是第几块
// for(int i = 0 ; i <= n ; i++)cout << '*' << pre[i] << endl;
printf("%.6lf\n" , pre[i]);
}
Code Jam 2008 APAC local onsites Problem C. Millionaire —— 概率DP的更多相关文章
- 2008 APAC local onsites C Millionaire (动态规划,离散化思想)
Problem You have been invited to the popular TV show "Would you like to be a millionaire?" ...
- GCJ 2008 APAC local onsites C Millionaire
时间复杂度很大.dp[i][j]表示第i轮 j这种状态的概率. #include<cstdio> #include<cstring> #include<cmath> ...
- GCJ2008 APAC local onsites C Millionaire
自己Blog的第一篇文章,嗯... 接触这道题,是从<挑战程序设计竞赛>这本书看来的,其实头一遍读题解,并没有懂.当然现在已经理解了,想想当初可能是因为考虑两轮的那张概率图的问题.于是决定 ...
- Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit
Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...
- Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...
- Google Code Jam 2008 Round 1A C Numbers(矩阵快速幂+化简方程,好题)
Problem C. Numbers This contest is open for practice. You can try every problem as many times as you ...
- ZOJ Problem Set - 3329(概率DP)
One Person Game Time Limit: 1 Second Memory Limit: 32768 KB Special Judge There is a very ...
- LuoguP2523 [HAOI2011]Problem c(概率DP)
傻逼概率\(DP\),熊大坐这,熊二坐这,两熊体积从右往左挤,挤到\(FFF\)没座位了就不合理了 否则就向左歇斯底里爬,每个\(FFF\)编号就组合一下,完闭 #include <iostre ...
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
随机推荐
- 第三百五十六天 how can I 坚持
一年了,三百五十六天.写个算法算下对不对. 今天突然想买辆自行车了.云马智行车,还是捷安特,好想买一辆. 网好卡.貌似少记了一天呢,357了.好快. 睡觉了,还没锻炼呢,太晚了. 1458748800 ...
- Event Functions
[Event Functions] A key concept in games programming is that of making changes to position, state an ...
- SOA和Web Service介绍
博客园中关于SOA和Web Service的介绍 http://www.cnblogs.com/talentbuilder/archive/2010/05/04/1727044.html http:/ ...
- halcon,C# 学习
Halcon学习之一:查询图像参数 1.get_grayval ( Image : : Row, Column : Grayval ) 计算Image图像中坐标为(Row,Column)的点的灰度值G ...
- 基于TF/IDF的聚类算法原理
一.TF/IDF描述单个term与特定document的相关性TF(Term Frequency): 表示一个term与某个document的相关性. 公式为这个term在document中出 ...
- SQL Server 批量插入数据的两种方法(转)
此文原创自CSDN TJVictor专栏:http://blog.csdn.net/tjvictor/archive/2009/07/18/4360030.aspx 在SQL Server 中插入一条 ...
- android wifi总结
大致可以分为四个主要的类ScanResult wifiConfiguration WifiInfo WifiManager (1)ScanResult,主要是通过wifi 硬件的扫描来获取一些周边的w ...
- 闲话Cache:始篇
Caching(缓存)在现代的计算机系统中是一项最古老最基本的技术.它存在于计算机各种硬件和软件系统中,比如各种CPU, 存储系统(IBM ESS, EMC Symmetrix…),数据库,Web服务 ...
- Flex随笔
-keep-generated-actionscript=true 默认的情况在flex中 对label进行字体加粗的时候,只能对英文的字体加粗,而中文的就不可以加粗: 为了能够使中文能够加粗,需要将 ...
- Parallel.ForEach , ThreadPool.QueueUserWorkItem
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...