题意:

三个色子有k1,2,k3个面每面标号(1-k1,1-k2,1-k3),一次抛三个色子,得正面向上的三个编号,若这三个标号和给定的三个编号a1,b1,c1对应则总和置零,否则总和加上三个色子标号和,直到总和不小于n时结束,求抛色子的期望次数。

分析:

该题状态好分析

dp[i]表示和为i时的期望次数,dp[0]是答案

dp[i]=sum(dp[i+tmp]*p[tmp])+dp[0]*p0+1(tmp是三个色子可得到的标号和);

第一次看到这样的方程不怎么解,看了题解才知道用迭代法,每个dp[i]里都包括dp[0];

令dp[i]=a[i]*dp[0]+b[i],带入上面的方程可得dp[i]=(sum(a[i+tmp]*p[tmp])+p0)*dp[0]+sum(b[i+tmp]*p[tmp])+1;

则a[i]=sum(a[i+tmp]*p[tmp])+p0,b[i]=sum(b[i+tmp]*p[tmp])+1;

则dp[0]=a[0]*dp[0]+b[0],求出答案;

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
double a[],b[],p[];
int n,k1,k2,k3,a1,b1,c1;
void solve(){
double tp=1.0/(k1*k2*k3);
memset(p,,sizeof(p));
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=;i<=k1;++i)
for(int j=;j<=k2;++j)
for(int k=;k<=k3;++k)
if(i!=a1||j!=b1||k!=c1)
p[i+j+k]+=tp;
for(int i=n;i>=;--i){
for(int j=;(i+j)<=n&&j<=k1+k2+k3;++j){
a[i]+=a[i+j]*p[j];
b[i]+=b[i+j]*p[j];
}
a[i]+=tp;
b[i]+=1.0;
}
printf("%.15lf\n",b[]/(1.0-a[]));
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&a1,&b1,&c1);
solve();
}
return ;
}

ZOJ 3329-One Person Game(概率dp,迭代处理环)的更多相关文章

  1. zoj 3329 One Person Game 概率DP

    思路:这题的递推方程有点麻烦!! dp[i]表示分数为i的期望步数,p[k]表示得分为k的概率,p0表示回到0的概率: dp[i]=Σ(p[k]*dp[i+k])+dp[0]*p0+1 设dp[i]= ...

  2. ZOJ 3329 One Person Game 概率DP 期望 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754 本题分数为0的概率不确定,所以不能从0这端出发. 设E[i]为到达成功所 ...

  3. zoj 3640 Help Me Escape 概率DP

    记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  4. HDU 4089 Activation:概率dp + 迭代【手动消元】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4089 题意: 有n个人在排队激活游戏,Tomato排在第m个. 每次队列中的第一个人去激活游戏,有可能 ...

  5. ZOJ 3502 Contest <状态压缩 概率 DP>

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3502 #include <iostream> #incl ...

  6. zoj 3640 Help Me Escape (概率dp 递归求期望)

    题目链接 Help Me Escape Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest w ...

  7. ZOJ 3329 Problem Set (期望dp)

    One Person Game There is a very simple and interesting one-person game. You have 3 dice, namely Die1 ...

  8. 【BZOJ 2878】 2878: [Noi2012]迷失游乐园 (环套树、树形概率DP)

    2878: [Noi2012]迷失游乐园 Description 放假了,小Z觉得呆在家里特别无聊,于是决定一个人去游乐园玩.进入游乐园后,小Z看了看游乐园的地图,发现可以将游乐园抽象成有n个景点.m ...

  9. poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP

    poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...

随机推荐

  1. dbgrid显示access备注信息

    procedure TfrmAllFind.DBGrid6DrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; C ...

  2. Solr查询详解

    前言:上节是关于Solr的开发准备工作:.NET开发过程中的全文索引使用技巧之Solr(http://www.cnblogs.com/johnwood/p/3447242.html) 这节重点是讲So ...

  3. Java学习笔记之:Java构造函数

    一.引言 构造函数是一种特殊的函数.其主要功能是用来在创建对象时初始化对象, 即为v对象成员变量赋初始值,总与new运算符一起使用在创建对象的语句中.构造函数与类名相同,可重载多个不同的构造函数. 构 ...

  4. python 利用smtp发送邮件,html格式

    def send_mail(to_list, sub, context):#sentmail to the maillist ''' to_list: 发送给谁 sub: 主题 context: 内容 ...

  5. 50. Pow(x, n)

    题目: Implement pow(x, n). 链接: http://leetcode.com/problems/powx-n/ 题解: 使用二分法求实数幂,假如不建立临时变量halfPow,直接r ...

  6. phantomjs使用说明

    phantomjs使用说明 12条评论   phantomjs实现了一个无界面的webkit浏览器.虽然没有界面,但dom渲染.js运行.网络访问.canvas/svg绘制等功能都很完备,在页面抓取. ...

  7. 转:Android 获取Root权限

    来自:http://blog.csdn.net/twoicewoo/article/details/7228940 import java.io.DataOutputStream; import an ...

  8. PHP中该怎样防止SQL注入?

    因为用户的输入可能是这样的: ? 1 value'); DROP TABLE table;-- 那么SQL查询将变成如下: ? 1 INSERT INTO `table` (`column`) VAL ...

  9. Eclipse - FindBugs Plugin 的安装和使用

    Eclipse -  FindBugs Plugin 的安装和使用 FindBugs is a static analysis tool that examines the classes in se ...

  10. hadoop2 环境的搭建(自动HA)

    zookeeper:hadoop112.hadoop113.hadoop114 namenode:hadoop110和hadoop111 datanode:hadoop112.hadoop113.ha ...