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

 1 int M , X  ;
 2 double P;
 3 double dp[2][(1 << 15) + 1];
 4 void solve()
 5 {
 6     int n = 1 << M;
 7     double *pre = dp[0] , *nxt = dp[1];
 8     memset(pre , 0 , sizeof(double) * (n + 1));
 9 ///    memset(pre , 0 , sizeof(pre)); 这样初始化是不行的,因为pre为一个double型的指针,不是整个数组。
10     pre[n] = 1.0;
11     for(int r = 0 ; r < M; r++)///枚举第几轮
12     {
13         for(int i = 0 ; i <= n ; i++)///枚举当前是哪种状态
14         {
15             int step = min(i , n - i);///如果step大于n / 2 , 等会儿转移的时候可能会超过n
16             double t = 0.0;
17             for(int j = 0 ; j <= step ; j++)///枚举当前的所有可能走法
18             {
19                 t = max(t , P * pre[i + j] + (1 - P) * pre[i - j]);///求出期望的最大值
20             }
21             nxt[i] = t;
22         }
23         swap(pre , nxt);///交换两个数组的值进行滚动
24     }
25     int i = (LL)X * n / 1000000;///找到X对应的是第几块
26 //    for(int i = 0 ; i <= n ; i++)cout << ‘*‘ << pre[i] << endl;
27     printf("%.6lf\n" , pre[i]);
28 } 
时间: 2024-10-26 18:08:00

Code Jam 2008 APAC local onsites Problem C. Millionaire —— 概率DP的相关文章

Millionaire(2008 APAC local onsites c)

---恢复内容开始--- 题意:最开始你有x元钱,要进行M轮赌博.每一轮赢的概率为P,你可以选择赌与不赌,如果赌也可以将所持的任意一部分钱作为赌注(可以是整数,也可以是小数).如果赢了,赌注将翻倍:输了赌注则没了.在M轮赌博结束后,如果你持有的钱在100万元以上,就可以把这些钱带回家.问:当你采取最优策略时,获得100万元以上的钱并带回家的概率是多少. 类型:动态规划&离散化思想 分析:由于每一轮的赌注是任意的,不一定为整数,因而有无限种可能,所以即便想穷竭搜索也无从着手.但如果能化连续为离散,

ZOJ Problem Set - 3329(概率DP)

One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very simple and interesting one-person game. You have 3 dice, namely Die1, Die2 and Die3. Die1 has K1 faces. Die2 has K2 faces. Die3 has K3 faces. All the

Google Code Jam 2012 Practice - Store Credit

Problem You receive a credit C at a local store and would like to buy two items. You first walk through the store and create a list L of all available items. From this list you would like to buy two items that add up to the entire value of the credit

Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and

Google Code Jam 2014 Round2

Google Code Jam Round2 晚上10点开始的,开始google一直上不去,然后开了个vpn就行了. 说说我的情况吧. P1就是某年noip普及组纪念品分组,贪心. p2是说给你一个排列,然后每次可以交换两个相邻的数,使得最后序列变为先上升后下降的样子.(n<=1000) 一开始题目看错了,以为是交换任意两个,然后愣了半天不会,去写后两题暴力了. (话说我Round1Cp1题目也看错了害的我逗了好久) 后来突然发现是adjacent elements...(<论英语学习的重要性

hdu 2993 MAX Average Problem (斜率优化dp入门)

MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5855    Accepted Submission(s): 1456 Problem Description Consider a simple sequence which only contains positive integers as

UVALive 6514:Crusher’s Code(概率dp)

题目链接 https://icpcarchive.ecs.baylor.edu/external/65/6514.pdf 题意:给出n个数(n<8) 求这n个数分别两个程序排成有序时,程序的期望迭代次数.排序程序如下. // Monty's Code while (!sorted(a)) { int i = random(n) ; int j = random(n) ; if (a[min(i,j)] > a[max(i,j)]) swap(a[i], a[j]) ; } //Carlos's

BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )

概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , 推推公式就可以 O( n ) , 但是 n 最大是99999999 , 怎么破....其实 n 很大时概率基本不动了...所以只需计算到某一个较大值时就可以停下来了... ----------------------------------------------------------------

Google Code Jam Round 1A 2015 Problem B. Haircut 二分

Problem You are waiting in a long line to get a haircut at a trendy barber shop. The shop has B barbers on duty, and they are numbered 1 through B. It always takes the kth barber exactly Mk minutes to cut a customer's hair, and a barber can only cut