Codeforces Gym 100338I TV Show DFS
来源:互联网 发布:想做淘宝刷单hao360 编辑:程序博客网 时间:2024/06/11 18:15
题目链接:
http://codeforces.com/gym/100338/attachments
题意:
一个人去参加电视有奖问答的节目,初始奖金为100元,每答对一道问题奖金翻倍,答错奖金清零。此外有一次保险机会:花费C的奖金,下一题可以答对奖金翻倍,答错奖金不清零。
现在给你答对每道题的概率,求最优答题策略的奖金期望。
题解:
http://blog.csdn.net/qq_15714857/article/details/48035161
枚举到第i题前离开 , 并且在第k题(k小于i)使用保险,注意k可以等于0,表示 不用
代码:
code 1:
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define MS(a) memset(a,0,sizeof(a))#define MP make_pair#define PB push_backconst int INF = 0x3f3f3f3f;const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//////////////////////////////////////////////////////////////////////////const int maxn = 1e5+10;double p[55],dp[55][55];int n,c;double ans;// 做到第t题 在x题之前离开 在第k题用保险,得到sum元的概率是pp【 p[1]*p[2]*p[3]*...void dfs(int t,int x,int k,double sum,double pp){ if(t == x){ dp[x][k] += sum*pp; ans = max(ans,dp[x][k]); return ; }else if(sum>=c && k==t){ dfs(t+1,x,k,(sum-c),pp*(1-p[t])); dfs(t+1,x,k,(sum-c)*2,pp*p[t]); } else dfs(t+1,x,k,sum*2,pp*p[t]);}int main(){ freopen("tvshow.in","r",stdin); freopen("tvshow.out","w",stdout); n=read(),c=read(); for(int i=1; i<=n; i++){ cin >> p[i]; p[i] /= 100; } for(int i=1; i<=n+1; i++) for(int k=0; k<i; k++) // k=0 可以不用保险 dfs(1,i,k,100.0,1.0); printf("%.10lf\n",ans); return 0;}// http://codeforces.com/gym/100338/attachments
code 2:
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define MS(a) memset(a,0,sizeof(a))#define MP make_pair#define PB push_backconst int INF = 0x3f3f3f3f;const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//////////////////////////////////////////////////////////////////////////const int maxn = 1e5+10;int n,c;double p[55];double dfs(int t,double sum,bool have){ if(t >= n){ return sum; } double tmp = max(sum,p[t]*dfs(t+1,sum*2,have)); double money = 0; if(sum>=c && have){ money += p[t] * dfs(t+1,(sum-c)*2,false); money += (1-p[t]) * dfs(t+1,(sum-c),false); } tmp = max(tmp,money); return tmp;}int main(){ freopen("tvshow.in","r",stdin); freopen("tvshow.out","w",stdout); cin >> n >> c; for(int i=0; i<n; i++){ cin >> p[i]; p[i] /= 100; } double ans = dfs(0,100.0,true); // true表示还有保险 printf("%.10lf\n",ans); return 0;}// http://codeforces.com/gym/100338/attachments
0 0
- Codeforces Gym 100338I TV Show DFS
- Gym 100338I TV show (dfs枚举)
- CodeForces Gym 100735I
- codeforces-gym-100187-J【dfs】
- codeforces Gym 101097 I Sticks
- Codeforces Gym 101164I Cubes
- Codeforces Gym 100463D Evil DFS
- Codeforces Gym 100650B Countdown DFS
- Codeforces-846B: Math Show(dfs+贪心)
- 【Codeforces Gym 100228 - I】Graph Dp
- codeforces Gym 101334 I IP Networks
- codeforces Gym 101341 I Matrix God
- Gym 101341G I love Codeforces 模拟
- Codeforces Gym 100623I Problem I. Important Wires
- ACdream1421 TV Show
- codeforces Gym 100187J J. Deck Shuffling dfs
- CodeForces Gym 100500A A. Poetry Challenge DFS
- Codeforces Gym 100650C The Game of Efil DFS
- 2017/02/28
- 现代操作系统与应用开发
- centos 7 开机启动项
- EventBus-的使用
- Shiro的认证和权限控制
- Codeforces Gym 100338I TV Show DFS
- centos 7 配置https
- 小白写基金——点滴积累
- JS之函数理解
- Swust OJ 001 Satellite Photographs
- hihocoder #1224 : 赛车 dfs
- 做项目开发后目前有的域名
- Volley深度完全解析
- Android中如何使用WIFI来连接ADB