题意:

三个色子有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. .net web部署(IIS Express && Nancy Self-Hosting)

    http://d.hatena.ne.jp/fkmt5/20140330/1396195246 [1]Nancy Web配置注意事项 添加url:netsh http add urlacl url=h ...

  2. js中的call、apply

    function qingyezhuA(a0, a1) { this.qingyezhuX = a0 + a1; } var qingyezhuObj1 = { }; qingyezhuA.apply ...

  3. leetcode 5 :Longest Palindromic Substring 找出最长回文子串

    题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  4. 从一点儿不会开始——Unity3D游戏开发学习(一)

    一些废话 我是一个windows phone.windows 8的忠实粉丝,也是一个开发者,开发数个windows phone应用和两个windows 8应用.对开发游戏一直抱有强烈兴趣和愿望,但奈何 ...

  5. 一步一步开发sniffer(Winpcap+MFC)(一)工欲善其事,必先配环境——配置winpcap开发环境(图文并茂,非常清楚)

    http://blog.csdn.net/litingli/article/details/5950962

  6. 实用Photoshop快捷键

    面板快捷键:shift+对应的快捷键调用同类工具 Ctrl + 点击面板------获取选取 Shift + F6-----------羽化 Alt + Delete---------填充前景色 Ct ...

  7. NDK 提示"undefined reference to xxx“的解决办法

    在Android.mk文件的 LOCAL_SRC_FILES后面加入包含该类或函数的文件,用\隔开,\后换行继续添加 例如 LOCAL_SRC_FILES := NDKTest.cpp\bncore. ...

  8. Linux文件与进程的Capability简介

    UID这种权限机制颗粒太粗,容易引起权利过剩(溢出),Linux引入了Capability:每个Capability系统内以一位Bit代表,OS内部使用64bit存储. 下面是android的capa ...

  9. 制作SM2证书

    前段时间将系统的RSA算法全部升级为SM2国密算法,密码机和UKey硬件设备大都同时支持RSA和SM2算法,只是应用系统的加解密签名验证需要修改,这个更改底层调用的加密动态库来,原来RSA用的对称加密 ...

  10. bzoj1997: [Hnoi2010]Planar

    2-SAT. 首先有平面图定理 m<=3*n-6,如果不满足这条件肯定不是平面图,直接退出. 然后构成哈密顿回路的边直接忽略. 把哈密顿回路当成一个圆, 如果俩条边交叉(用心去感受),只能一条边 ...