题目链接:Click here

Solution:

考虑设\(f(i,j)\)表示当前还有\(i\)张红牌,\(j\)张黑牌时的期望收益

易得状态转移方程:\(f(i,j)=\frac{i}{i+j}(f(i-1,j)+1)+\frac{j}{i+j}(f(i,j-1)-1)\)

事实上,由于采取最优策略,当此时期望为负数时,我们肯定是不取的,所以式子是这样的:

\[f(i,j)=max(0,\frac{i}{i+j}(f(i-1,j)+1)+\frac{j}{i+j}(f(i,j-1)-1))
\]

题目只给了64MB的空间,所以我们需要用滚动数组来优化空间

最后再对输出进行一些处理就可以了

Code:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int v=1e6;
int n,m,u=1;
double f[2][5001];
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main(){
n=read(),m=read();
for(int i=0;i<=n;i++){
u^=1;f[u][0]=i;
for(int j=1;j<=m;j++)
f[u][j]=max(0.0,1.0*i/(i+j)*(f[u^1][j]+1)+1.0*j/(i+j)*(f[u][j-1]-1));
}
printf("%.6lf",1.0*(ll){f[u][m]*v}/v);
return 0;
}

BZOJ1491 Red is good的更多相关文章

  1. 使用Red Gate Sql Data Compare 数据库同步工具进行SQL Server的两个数据库的数据比较、同步

    Sql Data Compare 是比较两个数据库的数据是否相同.生成同步sql的工具. 这一款工具由Red Gate公司出品,我们熟悉的.NET Reflector就是这个公司推出的,它的SQLTo ...

  2. 使用Red Gate Sql Compare 数据库同步工具进行SQL Server的两个数据库的结构比较、同步

    将测试版的项目同步(部署)到正式版的时候,两个数据库的结构比较与同步时,如果修改数据库的时候没有记录好修改了那些表,很难将两个数据库进行同步 RedGate Sql Compare使用简介说明: 1. ...

  3. 新年抢红包效果(New Year Red Packet)

    新年抢红包效果(New Year Red Packet) 晓娜的文章(微信公众号:migufe) 2016即将过去,我们将迎来新的一年2017,这里小编提前祝大家新年快乐!万事如意!那我们新年最开心的 ...

  4. KALI Linux problems & Study Red Hat | Ubuntu

    Problem When you ask some website with https head.you may met the problem  secure connection failed ...

  5. Red Gate(SQLToolbelt)SQL Server的安装与注册(破解)

    Red Gate(SQLToolbelt)是SQL Server辅佐工具 1.SQL Compare 比较和同步SQL Server数据库结构 2.SQL Data Compare 比较和同步SQL ...

  6. Red Hat Enterprise Server 6.0 安装Sendmail相关包

    由于需要在Linux服务器(Red Hat Enterprise Linux Server release 6.0)上配置邮件服务,需要安装Sendmail包,一般Sendmail的安装有两种方式:R ...

  7. Red Hat Enterprise Linux 6.6安装体验

    Red Hat Enterprise Linux 6.6的安装首界面有五个选项,这跟以前的Red Hat Enterprise Linux 5.x的安装界面是有一些区别的.   安装或者升级现有系统( ...

  8. Red Hat Enterprise Linux 各个版本以及发布日期

    Red Hat Enterprise Linux 7 Release/Update General Availability Date redhat-release Errata Date* Kern ...

  9. linux red hat 给普通用户开启root权限

    环境:虚拟机:red hat 6.5:root角色用户:普通用户:宏基笔记本:win7: 操作过程: 1.登录普通用户,进入图形界面(可以设置为启动登录进入命令行界面): 2.按Crl+ALT+F2进 ...

随机推荐

  1. XCode8.3真机调试设置

    本文使用XCode8.3.3 首先XCode->Preferncs,进入下面的界面 点击左下角“+”号,并输入账号,然后点击Manage Certificates,左下角添加IOS develo ...

  2. Redis配置主从时报错“Could not connect to Redis at 192.168.0.50:6379: Connection refused not connected>”

    配置Redis主从时,修改完从节点配置文件,然后报错 [root@Rich七哥-0-50 redis]# /opt/redis/redis-cli -h 192.168.0.50 Could not ...

  3. [Python3] 030 常用模块 os

    目录 os 1. os.getcwd() 2. os.chdir() 3. os.listdir() 4. os.makedir() 5. os.system() 6. os.getenv() 7. ...

  4. Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.

    Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org ...

  5. ubuntu中用命令创建数据库

    # switch to postgres account sudo su postgres # create a new postgres login: jetty; and set the pass ...

  6. python_操作MySQL 初解

    单文件操作数据库 import random import threading, multiprocessing import time, datetime import pymysql import ...

  7. 微信小程序的拖拽、缩放和旋转手势

    在开发中,有时会遇到像App中的手势那样的效果,下面就仿照App实现了一下. wxml部分: <view class="touch-container"> <vi ...

  8. Jquery复习(八)之遍历

    jQuery 遍历 - 祖先 parent() parents() parentsUntil() jQuery parent() 方法 parent() 方法返回被选元素的直接父元素. 该方法只会向上 ...

  9. Fliter设置字符编码,解决中文问题

    class EncodingFilter implements FileFilter{ private String encoding; @Override public boolean accept ...

  10. Laravel 中 Controller访问Model函数/常量

    <?php // User.php class User extends Model { ; //进行中 const USER_TYPE_TEST = 'test'; //测试用户 // 需要在 ...