Codeforces Gym 100338I TV Show 傻逼DFS,傻逼题
Problem I. TV Show
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88926#problem/I
Description
Charlie is going to take part in one famous TV Show. The show is a single player game. Initially the player has 100 dollars. The player is asked n questions, one after another. If the player answers the question correctly, the sum he has is doubled. If the answer is incorrect, the player gets nothing and leaves the show. Before each question the player can choose to leave the show and take away the prize he already has. Also once in the game the player can buy insurance. Insurance costs c dollars which are subtracted from the sum the player has before the question. Insurance has the following effect: if the player answers the question correctly his prize is doubled as usually, if the player answers incorrectly the prize is not doubled, but the game continues. The player must have more than c dollars to buy insurance. Charlie’s friend Jerry works on TV so he managed to steal the topics of the questions Charlie will be asked. Therefore for each question i Charlie knows pi — the probability that he will answer this question correctly. Now Charlie would like to develop the optimal strategy to maximize his expected prize. Help him.
Input
Output
Output one real number — the expected prize of Charlie if he follows the optimal strategy. Your answer must have relative or absolute error within 10−8 .
Sample Input
2 100
50 50
Sample Output
100
HINT
题意
你正在参加答题活动,每次你可以选择答还是不答,如果你答对了,奖金翻倍,如果答错了,1分钱也拿不到并且滚蛋
答题中你可以买一个保险,使得自己下次就算答错了,也不会有惩罚
题解:
我真是日了,我想了一个小时这个傻逼DFS,比赛中没AC
我回去写了N份这道题的不同姿势,全部WA
结果告诉我,是我读题读错了,是我读题读错了,我真是……
这傻逼题
傻逼DFS就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** double p[];
double ans=;
double dp[][];
int n,c;
void dfs(int t,int x,int y,double num,double pp,int k)
{k=;//谁TM告诉我保险如果没用掉,下回合可以接着用的? if(t==x)
{
dp[x][y]+=num*pp;
ans = max(dp[x][y],ans);
return;
}
else if(k==)
{
dfs(t+,x,y,num*,pp*p[t],);
dfs(t+,x,y,num,pp*(-p[t]),);
}
else if(t==y&&num>=c)
{
dfs(t+,x,y,(num-c)*,pp*p[t],);
dfs(t+,x,y,(num-c),pp*(-p[t]),);
}
else
dfs(t+,x,y,num*,pp*p[t],);
}
int main()
{
freopen("tvshow.in","r",stdin);
freopen("tvshow.out","w",stdout);
n=read(),c=read();
for(int i=;i<=n;i++)
{
cin>>p[i];
p[i]/=;
}
for(int j=;j<=n+;j++)
{
for(int k=;k<j;k++)
{
dfs(,j,k,100.0,1.0,);
}
}
printf("%.10lf\n",ans);
}
Codeforces Gym 100338I TV Show 傻逼DFS,傻逼题的更多相关文章
- codeforces gym #101987K -TV ShowGame(2-SAT)
题目链接: https://codeforces.com/gym/101987 题意: 有长度为$n$的只包含$B,R$的字符串 有m种关系,每个关系说出三个位置的确切字符 这三个位置的字符最多有一个 ...
- Codeforces Gym 100650C The Game of Efil DFS
The Game of EfilTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- 【转】eclipse中egit插件使用
原文网址:http://my.oschina.net/songxinqiang/blog/192567 eclipse和git这个两个工具的使用人数都是相当多的,在eclipse里面也有egit插件来 ...
- shell小技巧
# awk '{a[$1]++;a[$2]++}END{for (i in a)print i "\t" a[i]}' list | grep -w 2 | awk '{print ...
- Spring Bean基本管理--bean注入方式汇总
依赖注入方式:Spring支持两种依赖注入方式,分别是属性注入和构造函数注入.还有工厂方法注入方式. 依赖注入还分为:注入依赖对象可以采用手工装配或自动装配,在实际应用开发中建议使用手工装配,因为自动 ...
- DzzOffice管理员登陆方法和管理员应用介绍
DzzOffice的管理方式类似于windows的管理方式,是直接在桌面中,通过管理员应用进行系统中的所有管理里工作. 1.访问http://www.domain.com (你站点的访问地址) 2.点 ...
- 排序算法:七大排序算法的PHP实现
由于最近在找工作,面试中难免会遇到一些算法题,所以就用PHP把七大排序算法都实现了一遍,也当做是一种复习于沉淀. 冒泡排序 2. 选择排序 3. 插入排序 4. 快速排序 5. 希尔排序 6. 归并排 ...
- C++ 我想这样用(五)
上一篇说了[C with Class]语法的第一部分,下面继续第二部分: 第二部分:面向过程的编程风格 什么是面向过程我想如果你还不知道,那你绝对不是C程序员!其实我个人感觉面向过程.模块式的C编程风 ...
- 开源框架DNN使用01
我先简单地介绍下我个人对于DNN的浅显理解吧. 我觉得对于刚接触的人来说首先理解DNN的原理,大框架是很重要的.它整个网站其实是没几个页面的,从源码上就可以看出, 一个Default页.一个Error ...
- 给sublime text添加ubuntu launcher快捷方式
1.下载sublime text 2文件,解压并复制到/opt目录,文件夹名称不要含有空格 2.在/usr/share/applications目录下新建sublime_text.desktop文件 ...
- 使用DBCC SHOW_STATISTICS展示索引的统计信息
在开始之前搭建演示环境: USE master GO SET NOCOUNT ON --创建表结构 IF OBJECT_ID(N'ClassA', N'U') IS NOT NULL DROP TAB ...
- TCMalloc优化MySQL、Nginx、Redis内存管理
TCMalloc(Thread-Caching Malloc)与标准glibc库的malloc实现一样的功能,但是TCMalloc在效率和速度效率都比标准malloc高很多.TCMalloc是 goo ...