GCJ--Millionaire (2008 APAC local onsites C)
来源:互联网 发布:阿里云 网站端口 编辑:程序博客网 时间:2024/06/05 19:52
Problem
You have been invited to the popular TV show "Would you like to be a millionaire?".Of course you would!
The rules of the show are simple:- Before the game starts, the host spins a wheel of fortune todetermine P, the probability of winning each bet.
- You start out with some money: X dollars.
- There are M rounds of betting. In each round, you can bet anypart of your current money, including none of it or all of it. The amount is not limited to whole dollars or whole cents.
If you win the bet, your total amount of money increases by the amount you bet. Otherwise, your amount of money decreases by the amount you bet.
- After all the rounds of betting are done, you get to keep yourwinnings (this time the amount is rounded down to whole dollars) only if you have accumulated $1000000 or more. Otherwise you get nothing.
Given M, P and X, determine your probability of winning at least $1000000 if you play optimally (i.e. you play so that you maximize yourchances of becoming a millionaire).
Input
The first line of input gives the number of cases, N.
Each of the following N lines has the format "M P X", where:
- M is an integer, the number of rounds of betting.
- P is a real number, the probability of winning each round.
- X is an integer, the starting number of dollars.
Output
For each test case, output one line containing "Case #X: Y", where:
- X is the test case number, beginning at 1.
- Y is the probability of becoming a millionaire, between 0 and 1.
Answers with a relative or absolute error of at most 10-6 will be considered correct.
Limits
1 ≤ N ≤ 100
0 ≤ P ≤ 1.0, there will be at most 6 digits after the decimal point.
1 ≤ X ≤ 1000000
Small dataset
1 ≤ M ≤ 5
Large dataset
1 ≤ M ≤ 15
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define MAX_M 25using namespace std;typedef long long ll;int M,X;int T,temp;double P;double dp[2][(1<<MAX_M)+1];void solve(){int n=1<<M;double *prv =dp[0], *nxt=dp[1];memset(prv,0,sizeof(double)*(n+1));prv[n]=1.0;for(int r=0;r<M;r++){for(int i=0;i<=n;i++){int jub=min(i,n-i);double t=0.0;for(int j=0;j<=jub;j++){t=max(t,P*prv[i+j]+(1-P)*prv[i-j]);}nxt[i]=t;}swap(prv,nxt);}int i=(ll) X*n/1000000;printf("Case #%d: %.6lf\n",temp-T,prv[i]);}int main(){freopen("C-large-practice.in","r",stdin);freopen("output.out","w",stdout);cin>>T;temp=T;while(T--){scanf("%d%lf%d",&M,&P,&X);solve();}return 0; }
- GCJ--Millionaire (2008 APAC local onsites C)
- GCJ--Millionaire (2008 APAC local onsites C)
- GCJ 2008 APAC local onsites C Millionaire
- GCJ 2008 APAC local onsites C(Millionaire) (dp+离散化)
- 【翻译】GCJ 2008 APAC local onsites C Millionaire 题解
- 2008 APAC local onsites Problem C. Millionaire
- Millionaire 2008APAC local onsites C
- Code Jam 2008 APAC local onsites Problem C. Millionaire —— 概率DP
- codejam 2008 APAC local onsites C 概率dp
- gcj 2008 apac problem c
- google codejam 2008 APAC local onsites , Problem A What are Birds?
- 132_millionarie 百万赌博问题 (2008 APAC local onsite C)
- Millionaire
- Millionaire
- 2016 GCJ R1 C
- GCJ Round 1A 2008 Problem C. Numbers
- Round C APAC Test 2016
- apac
- JSON教程
- map的emplace方法
- java JNI本地方法调用的使用
- 文章标题
- Python计算机视觉:第一章 图像处理基础
- GCJ--Millionaire (2008 APAC local onsites C)
- 【java】----日期函数大全
- Python计算机视觉:第二章 图像局部描述符
- Uva 10474
- Android为什么选择binder,及Binder设计与实现初步讲解
- 反转链表
- 通过简单的汇编代码了解计算机的工作原理
- 资格考试_第三章_证券投资基金的类型
- 正则表达式的使用