To Bet or Not To Bet

Time Limit: 1000MS Memory Limit: 10000K

Total Submissions: 1668 Accepted: 541

Description

Alexander Charles McMillan loves to gamble, and during his last trip to the casino he ran across a new game. It is played on a linear sequence of squares as shown below.

A chip is initially placed on the Start square. The player then tries to move the chip to the End square through a series of turns, at which point the game ends. In each turn a coin is fl

ipped: if the coin is heads the chip is moved one square to the right and if the coin is tails the chip is moved two squares to the right (unless the chip is one square away from the End square, in which case it just moves to the End square). At that point, any instruction on the square the coin lands on must be followed. Each instruction is one of the following:

1. Move right n squares (where n is some positive integer)

2. Move left n squares (where n is some positive integer)

3. Lose a turn

4. No instruction

After following the instruction, the turn ends and a new one begins. Note that the chip only follows the instruction on the square it lands on after the coin flip. If, for example, the chip lands on a square that instructs it to move 3 spaces to the left, the move is made, but the instruction on the resulting square is ignored and the turn ends. Gambling for this game proceeds as follows: given a board layout and an integer T, you must wager whether or not you think the game will end within T turns.

After losing his shirt and several other articles of clothing, Alexander has decided he needs professional help-not in beating his gambling addiction, but in writing a program to help decide how to bet in this game.

Input

Input will consist of multiple problem instances. The first line will consist of an integer n indicating the number of problem instances. Each instance will consist of two lines: the first will contain two integers m and T (1 <= m <= 50, 1 <= T <= 40), where m is the size of the board excluding the Start and End squares, and T is the target number of turns. The next line will contain instructions for each of the m interior squares on the board. Instructions for the squares will be separated by a single space, and a square instruction will be one of the following: +n, -n, L or 0 (the digit zero). The first indicates a right move of n squares, the second a left move of n squares, the third a lose-a-turn square, and the fourth indicates no instruction for the square. No right or left move will ever move you off the board.

Output

Output for each problem instance will consist of one line, either

Bet for. x.xxxx

if you think that there is a greater than 50% chance that the game will end in T or fewer turns, or

Bet against. x.xxxx

if you think there is a less than 50% chance that the game will end in T or fewer turns, or

Push. 0.5000

otherwise, where x.xxxx is the probability of the game ending in T or fewer turns rounded to 4 decimal places. (Note that due to rounding the calculated probability for display, a probability of 0.5000 may appear after the Bet for. or Bet against. message.)

Sample Input

5

4 4

0 0 0 0

3 3

0 -1 L

3 4

0 -1 L

3 5

0 -1 L

10 20

+1 0 0 -1 L L 0 +3 -7 0

Sample Output

Bet for. 0.9375

Bet against. 0.0000

Push. 0.5000

Bet for. 0.7500

Bet for. 0.8954

概率DP题目,

递推即可,

#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <string> using namespace std;
#define MAX 999999
char a[55];
int m,t;
double dp[55][55];
int b[55];
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
memset(dp,0,sizeof(dp));
memset(b,0,sizeof(b));
scanf("%d%d",&m,&t);
for(int i=1;i<=m;i++)
{
scanf("%s",a); if(a[0]=='L')
b[i]=MAX;
else
sscanf(a,"%d",&b[i]);
}
b[0]=0;b[m+1]=0;b[m+2]=-1;
dp[0][0]=1.0;
for(int i=0;i<t;i++)
{
for(int j=0;j<m+1;j++)
{
if(b[j+1]==MAX)
dp[i+2][j+1]+=dp[i][j]*0.5;
else
dp[i+1][j+b[j+1]+1]+=dp[i][j]*0.5;
if(b[j+2]==MAX)
dp[i+2][j+2]+=dp[i][j]*0.5;
else
dp[i+1][j+b[j+2]+2]+=dp[i][j]*0.5;
}
}
double ans=0;
for(int i=0;i<=t;i++)
ans+=dp[i][m+1];
if(ans>0.5)
printf("Bet for. %.4f\n",ans);
else if(ans==0.5)
printf("Push. 0.5000\n");
else if(ans<0.5)
printf("Bet against. %.4f\n",ans); }
return 0;
}

POJ-1644 To Bet or Not To Bet(概率DP)的更多相关文章

  1. poj 2151 Check the difficulty of problems(概率dp)

    poj double 就得交c++,我交G++错了一次 题目:http://poj.org/problem?id=2151 题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 问 ...

  2. POJ 2151 Check the difficulty of problems:概率dp【至少】

    题目链接:http://poj.org/problem?id=2151 题意: 一次ACM比赛,有t支队伍,比赛共m道题. 第i支队伍做出第j道题的概率为p[i][j]. 问你所有队伍都至少做出一道, ...

  3. POJ 2151 Check the difficulty of problems (概率dp)

    题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的 ...

  4. UVA 1541 - To Bet or Not To Bet(概率递推)

    UVA 1541 - To Bet or Not To Bet 题目链接 题意:这题题意真是神了- -.看半天,大概是玩一个游戏,開始在位置0.终点在位置m + 1,每次扔一个硬币,正面走一步,反面走 ...

  5. UVA 1541 - To Bet or Not To Bet 记忆化DP概率

    Alexander Charles McMillan loves to gamble, and during his last trip to the casino he ran across a n ...

  6. poj 3071 Football(概率dp)

    id=3071">http://poj.org/problem? id=3071 大致题意:有2^n个足球队分成n组打比赛.给出一个矩阵a[][],a[i][j]表示i队赢得j队的概率 ...

  7. 【POJ】2151:Check the difficulty of problems【概率DP】

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8903   ...

  8. 【POJ 2750】 Potted Flower(线段树套dp)

    [POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4566   ...

  9. POJ 2096 Collecting Bugs (概率DP,求期望)

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

随机推荐

  1. 本地推送UILocalNotification(转)

    1.增加一个本地推送 //设置20秒之后 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:]; //chuagjian一个本地推送 UILoca ...

  2. Hibernate_day04讲义_使用Hibernate完成对客户查询的优化

  3. JSON调试找不到 net.sf.ezmorph.Morpher

    JSON中,java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher问题解决 使用JSON,在SERVLET或者STRUTS的ACTION中取得数据 ...

  4. c++学习笔记—动态内存与智能指针浅析

    我们的程序使用内存包含以下几种: 静态内存用来保存局部static对象.类static数据成员以及定义在任何函数之外的变量,在使用之前分配,在程序结束时销毁. 栈内存用来保存定义在函数内部的非stat ...

  5. 日记整理---->2016-11-21

    2016-11-21简单的总结一下学到的知识点.作为一个目标而存在的东西,总是那么美丽而优雅. 一.PE中事务的编写 getTransactionTemplate().execute(new Tran ...

  6. Makefile 链接静态库

    Linux的静态库是以.a结尾的,要连接静态库有两种方法,一种是在编译命令最后直接加上库路径/库名称. 例如你的库在绝对目录/lib/libtest.a下面你就可以这样来编译$(CC) $(CFLAG ...

  7. initializer element is not constant 问题

    在Ubuntu下,比葫芦画瓢,写了一个程序,居然报错!!!! #include <stdio.h> ; int j = *(int *)(&i) ; int main (int a ...

  8. 怎样用SQL语句查看查询的性能指标

    一.SET STATISTICS IO  (有关TSQL语句查询所产生的磁盘活动量) 扫描计数:在查询中涉及到的表被访问的次数: 逻辑读取:从数据缓冲中读取的数据页数: 物理读取:从物理磁盘中往缓冲读 ...

  9. css3整理--box-shadow

    box-shadow语法:(想法:用阴影来做边框,就不会出现动态改变边框宽度而产生的重排问题) 对象选择器{box-shadow:投影方式 X轴偏移量 Y轴偏移量 阴影模糊半径 阴影扩展半径 阴影颜色 ...

  10. 在jmeter测试中模拟不同的带宽环境

    怎么去测试在手机app中和在web的不同的连接速度对服务器的影响呢? 大部分情况下,手机终端用户通过移动网络访问网站.所以在不同的网络连接数据下,我们的网站或程序可以同时处理多少链接?今天,这篇文件就 ...