Activation HDU - 4089(概率dp)
But before starting the game, he must first activate the product on the official site. There are too many passionate fans that the activation server cannot deal with all the requests at the same time, so all the players must wait in queue. Each time, the server deals with the request of the first player in the queue, and the result may be one of the following, each has a probability:
1. Activation failed: This happens with the probability of p1. The queue remains unchanged and the server will try to deal with the same request the next time.
2. Connection failed: This happens with the probability of p2. Something just happened and the first player in queue lost his connection with the server. The server will then remove his request from the queue. After that, the player will immediately connect to the server again and starts queuing at the tail of the queue.
3. Activation succeeded: This happens with the probability of p3. Congratulations, the player will leave the queue and enjoy the game himself.
4. Service unavailable: This happens with the probability of p4. Something just happened and the server is down. The website must shutdown the server at once. All the requests that are still in the queue will never be dealt.
Tomato thinks it sucks if the server is down while he is still waiting in the queue and there are no more than K-1 guys before him. And he wants to know the probability that this ugly thing happens.
To make it clear, we say three things may happen to Tomato: he succeeded activating the game; the server is down while he is in the queue and there are no more than K-1 guys before him; the server is down while he is in the queue and there are at least K guys before him.
Now you are to calculate the probability of the second thing.
InputThere are no more than 40 test cases. Each case in one line, contains three integers and four real numbers: N, M (1 <= M <= N <= 2000), K (K >= 1), p1, p2, p3, p4 (0 <= p1, p2, p3, p4 <= 1, p1 + p2 + p3 + p4 = 1), indicating there are N guys in the queue (the positions are numbered from 1 to N), and at the beginning Tomato is at the Mth position, with the probability p1, p2, p3, p4 mentioned above.OutputA real number in one line for each case, the probability that the ugly thing happens.
The answer should be rounded to 5 digits after the decimal point.
Sample Input
2 2 1 0.1 0.2 0.3 0.4
3 2 1 0.4 0.3 0.2 0.1
4 2 3 0.16 0.16 0.16 0.52
Sample Output
0.30427
0.23280
0.90343
令 dp[i][j] 表示一共有 i 个人,并且 tomato 在第 j 个位置时,达到最终状态的概率。
那么有三种情况:
1.j == 1 : dp[i][j] = p1 * dp[i][j] + p2 * dp[i][i] + p4
2.2 <= j <= k : dp[i][j] = p1 * dp[i][j] + p2 * dp[i][j-1] + p3 * dp[i-1][j-1] + p4
3.k < j <= i : dp[i][j] = p1 * dp[i][j] + p2 * dp[i][j-1] + p3 * dp[i-1][j-1]
移项化简得
1.j == 1 : dp[i][j] = p21 * dp[i][i] + p41
2.2 <= j <= k : dp[i][j] = p21 * dp[i][j-1] + p31 * dp[i-1][j-1] + p41
3.k < j <= i : dp[i][j] = p21 * dp[i][j-1] + p31 * dp[i-1][j-1]
其中p21 = p2 / (1 - p1), p31 = p3 / (1 - p1), p41 = p4 / (1 - p1).
此时当计算到 i 时, dp[i-1][] 的值已经全部求出来了,所以可以把后面部分看成常数
1.j == 1 : dp[i][j] = p21 * dp[i][i] + c[j] c[j] = p41
2.2 <= j <= k : dp[i][j] = p21 * dp[i][j-1] + c[j] c[j] = p31 * dp[i-1][j-1] + p41
3.k < j <= i : dp[i][j] = p21 * dp[i][j-1] + c[j] c[j] = p31 * dp[i-1][j-1]
然后 dp[i][i] 通过 2、3 式推到 dp[i][1], 然后在用 1 代入 dp[i][1], 求出 dp[i][i], 其式是
dp[i][i] = p21^(i) * dp[i][i] + Σ(p21^(i-x) * c[x])
然后就可以把 dp[i][] 的值都求出来,最后的答案就是dp[n][m]
/*
.
';;;;;.
'!;;;;;;!;`
'!;|&#@|;;;;!:
`;;!&####@|;;;;!:
.;;;!&@$$%|!;;;;;;!'.`:::::'.
'!;;;;;;;;!$@###&|;;|%!;!$|;;;;|&&;.
:!;;;;!$@&%|;;;;;;;;;|!::!!:::;!$%;!$%` '!%&#########@$!:.
;!;;!!;;;;;|$$&@##$;;;::'''''::;;;;|&|%@$|;;;;;;;;;;;;;;;;!$;
;|;;;;;;;;;;;;;;;;;;!%@#####&!:::;!;;;;;;;;;;!&####@%!;;;;$%`
`!!;;;;;;;;;;!|%%|!!;::;;|@##%|$|;;;;;;;;;;;;!|%$#####%;;;%&;
:@###&!:;;!!||%%%%%|!;;;;;||;;;;||!$&&@@%;;;;;;;|$$##$;;;%@|
;|::;;;;;;;;;;;;|&&$|;;!$@&$!;;;;!;;;;;;;;;;;;;;;;!%|;;;%@%.
`!!;;;;;;;!!!!;;;;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!;;;;!%%%&#&%$&: .|%;:!&%`
!@&%;;;;;;;||;;;:''::;;%$!;;;;;;;|&@%;!$; `%&%!!$&:
'$$|;!!!!;;||;;;;;;;;;;%%;;;;;;;|@@|!$##; !$!;:!$&:
|#&|;;;;;;!||;;;;;;;;!%|;;;;!$##$;;;;|%' `%$|%%;|&$'
|&%!;;;;;;|%;;;;;;;;$$;;;;;;|&&|!|%&&; .:%&$!;;;:!$@!
`%#&%!!;;;;||;;;;;!$&|;;;!%%%@&!;;;!!;;;|%!;;%@$!%@!
!&!;;;;;;;;;||;;%&!;;;;;;;;;%@&!;;!&$;;;|&%;;;%@%`
'%|;;;;;;;;!!|$|%&%;;;;;;;;;;|&#&|!!||!!|%$@@|'
.!%%&%'`|$; :|$#%|@#&;%#%.
*/
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pii pair<int, int>
#define INOPEN freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 2e3 + ;
const int maxm = 1e5 + ;
const int mod = 1e9 + ;
const ll INF = 1e18 + ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
using namespace std; int n, m, k;
int cas, tol, T; double c[maxn];
double pp[maxn];
double dp[maxn][maxn]; int main() {
double p1, p2, p3, p4;
while(~scanf("%d%d%d%lf%lf%lf%lf", &n, &m, &k, &p1, &p2, &p3, &p4)) {
if(fabs(p4) <= eps) {
printf("0.00000\n");
continue;
}
double p21 = p2 / ( - p1);
double p31 = p3 / ( - p1);
double p41 = p4 / ( - p1);
pp[] = 1.0;
for(int i=; i<=n; i++)
pp[i] = pp[i-] * p21;
dp[][] = p41 / ( - p21);
c[] = p41;
for(int i=; i<=n; i++) {
for(int j=; j<=i; j++) {
if(j == ) c[j] = p41;
else if(j <= k) c[j] = p31 * dp[i-][j-] + p41;
else c[j] = p31 * dp[i-][j-];
}
double tmp = ;
for(int j=; j<=i; j++) {
tmp += pp[i-j] * c[j];
}
dp[i][i] = tmp / (1.0 - pp[i]);
dp[i][] = p21 * dp[i][i] + c[];
for(int j=; j<i; j++) {
dp[i][j] = p21 * dp[i][j-] + c[j];
}
}
for(int i=; i<=n; i++) {
for(int j=; j<=i; j++) {
printf("%f%c", dp[i][j], j==i ? '\n' : ' ');
}
}
printf("%.5f\n", dp[n][m]);
}
return ;
}
Activation HDU - 4089(概率dp)的更多相关文章
- hdu 4089 概率dp
/* 题目大意:注册一款游戏需要排队,一共有四种事件: 1.注册失败,队列不变,概率为p1 2.注册过程中断开连接,正在注册的人排到队列的末尾,概率为p2 3.注册成功,移出队列,概率为p3 4.服务 ...
- HDU 4599 概率DP
先推出F(n)的公式: 设dp[i]为已经投出连续i个相同的点数平均还要都多少次才能到达目标状态. 则有递推式dp[i] = 1/6*(1+dp[i+1]) + 5/6*(1+dp[1]).考虑当前这 ...
- HDU 5001 概率DP || 记忆化搜索
2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP 測 ...
- hdu 3853 概率dp
题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...
- HDU 4815 概率dp,背包
Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K ( ...
- hdu 4050(概率dp)
算是挺简单的一道概率dp了,如果做了前面的聪聪于可可的话,这题不需要什么预处理,直接概率dp就行了... #include <stdio.h> #include <stdlib.h& ...
- Activation HDU - 4089 (概率DP)
kuangbin的博客 强 #include <bits/stdc++.h> using namespace std; const int MAXN = 2005; const doubl ...
- HDU 4405 (概率DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 题目大意:飞行棋.如果格子不是飞行点,扔骰子前进.否则直接飞到目标点.每个格子是唯一的飞行起点 ...
- hdu 4336 概率dp + 状压
hdu 4336 小吃包装袋里面有随机赠送一些有趣的卡片,如今你想收集齐 N 张卡片.每张卡片在食品包装袋里出现的概率是p[i] ( Σp[i] <= 1 ), 问你收集全部卡片所需购买的食品数 ...
随机推荐
- Easyui datagrid 设置内容超过单元格宽度时自动换行显示
datagrid 设置内容超过单元格宽度时自动换行显示 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3 问题描述 单元格内容超过单元格宽度不会自动化换行.如下 ...
- C#获得指定目录床架时间、更新时间和最后访问时间等信息的代码
将做工程过程常用的内容片段备份一次,下面的内容内容是关于C#获得指定目录床架时间.更新时间和最后访问时间等信息的内容,希望能对小伙伴们也有用. using System;using System.IO ...
- JavaScript中的闭包和作用域链
这部分几乎是JavaScript中最难的部分,也是面试官最爱问的地方. 下面的内容是我以前写的<JavaScript学习手册>中被客户删除的部分,理由听起来有点诡异:太难.
- 获取spring security用户相关信息
在JSP中获得 使用spring security的标签库 在页面中引入标签 <%@ taglib prefix="sec" uri="http://www.spr ...
- Linux AIDE(文件完整性检测)
一.AIDE的概念 AIDE:Advanced Intrusion Detection Environment,是一款入侵检测工具,主要用途是检查文档的完整性.AIDE在本地构造了一个基准的数据库,一 ...
- [经验总结] 从其它sheet页引用数据生成图表时没有图例的解决办法
1.先给出一个在有数据区域的sheet页中生成的图表,比较全,图表和图例全部都有,如下图: 2.但是如果在其它 sheet页中引用该有数据的sheet数据时并生成图表,生成的图表只有图表区域显示,图例 ...
- luffy项目后台drf搭建(1)
一 进入虚拟环境 打开crm,输入命令 workon luffy 虚拟环境使用文档 二 安装基本类库 pip install django pip install PymySQL pip instal ...
- KafkaManager编译安装使用(支持kerberos认证)
为了能够方便的查看及管理Kafka集群,yahoo提供了一个基于Web的管理工具(Kafka-Manager). 这个工具可以方便的查看集群中Kafka的Topic的状态(分区.副本及消息量等),支持 ...
- DISK 100% BUSY,谁造成的?(ok)
iostat等命令看到的是系统级的统计,比如下例中我们看到/dev/sdb很忙,如果要追查是哪个进程导致的I/O繁忙,应该怎么办? # iostat -xd ... Device: rrqm/s wr ...
- centos查看系统信息命令
1.cd - :返回上次所在的目录 2.查看系统版本 cat /etc/redhat-release 3.查看linux内核版本1)cat /proc/version 2) uname -a3) un ...