After 4 years' waiting, the game "Chinese Paladin 5" finally comes out. Tomato is a crazy fan, and luckily he got the first release. Now he is at home, ready to begin his journey. 
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)的更多相关文章

  1. hdu 4089 概率dp

    /* 题目大意:注册一款游戏需要排队,一共有四种事件: 1.注册失败,队列不变,概率为p1 2.注册过程中断开连接,正在注册的人排到队列的末尾,概率为p2 3.注册成功,移出队列,概率为p3 4.服务 ...

  2. HDU 4599 概率DP

    先推出F(n)的公式: 设dp[i]为已经投出连续i个相同的点数平均还要都多少次才能到达目标状态. 则有递推式dp[i] = 1/6*(1+dp[i+1]) + 5/6*(1+dp[1]).考虑当前这 ...

  3. HDU 5001 概率DP || 记忆化搜索

    2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP  測 ...

  4. hdu 3853 概率dp

    题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...

  5. HDU 4815 概率dp,背包

    Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K ( ...

  6. hdu 4050(概率dp)

    算是挺简单的一道概率dp了,如果做了前面的聪聪于可可的话,这题不需要什么预处理,直接概率dp就行了... #include <stdio.h> #include <stdlib.h& ...

  7. Activation HDU - 4089 (概率DP)

    kuangbin的博客 强 #include <bits/stdc++.h> using namespace std; const int MAXN = 2005; const doubl ...

  8. HDU 4405 (概率DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 题目大意:飞行棋.如果格子不是飞行点,扔骰子前进.否则直接飞到目标点.每个格子是唯一的飞行起点 ...

  9. hdu 4336 概率dp + 状压

    hdu 4336 小吃包装袋里面有随机赠送一些有趣的卡片,如今你想收集齐 N 张卡片.每张卡片在食品包装袋里出现的概率是p[i] ( Σp[i] <= 1 ), 问你收集全部卡片所需购买的食品数 ...

随机推荐

  1. C#字符串倒置函数的代码

    把内容过程比较常用的内容珍藏起来,下边内容内容是关于C#字符串倒置函数的内容. public static string Reverse(string ReverseString) { String ...

  2. Chrome浏览器,处理input自动填充时带黄色背景色

    /*Chrome浏览器打开网页,input自动赋值时,会带上屎黄色的背景色,下面是通过延长增加自动填充背景色的方式, 让用户感受不到样式的变化*/ input:-webkit-autofill, in ...

  3. SQL Sever AlwaysOn的数据同步原理

    1. SQL Server AlwaysOn数据同步基本工作 AlwaysOn 副本同步需要完成三件事: 1.把主副本上发生的数据变化记录下来. 2.把这些记录传输到各个辅助副本. 3.把数据变化在辅 ...

  4. 关于SQL数据库 msdb.dbo.sp_send_dbmail 函数发送邮件的几个实例

    在推行系统中,时不时会有用户提出希望系统能自动推送邮件,由于手头的工具和能力有限,不少需求都借助于sql server的邮件触发来实现. 步骤: 1.配置邮箱.步骤略,网上有不少帖子说明,手工直接在管 ...

  5. 【eclipse】mybatis配置文件创建与mapper接口文件创建

    什么是mybatis: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射. mybatis配置文件: <?xml version="1.0" ...

  6. 一天一个Linux命令--find

    文件查找:(以find为主)  which:查找命令字所在的位置  locate:模糊匹配(只要包含关键字的文件都查找出来)         不是实时的,基于数据库查找, updatedb升级loca ...

  7. Flex Builder 4.6切换语言

    一.修改Flex builder 1.用无格式编辑器打开FlashBuilder.ini 2.把zh_CN替换成"en_US" 二.修改MyEclipse插件 1.用无格式编辑器打 ...

  8. 【Python 01】Python可以做什么

    Python学习未来方向: 1.数据分析 2.自然语言处理 3.社交网络分析 4.人工智能 5.深度学习 6.计算机视觉 7.网络爬虫 8.量化交易

  9. .NET CORE学习笔记系列(2)——依赖注入[5]: 创建一个简易版的DI框架[下篇]

    为了让读者朋友们能够对.NET Core DI框架的实现原理具有一个深刻而认识,我们采用与之类似的设计构架了一个名为Cat的DI框架.在上篇中我们介绍了Cat的基本编程模式,接下来我们就来聊聊Cat的 ...

  10. 如何给python程序加密

    在实际的工作中,有时候我们需要部署自己的Python应用,但这时候我们并不希望别人能够看到自己的Python源程序.因此,我们需要为自己的源代码进行加密,Python已经为我们提供了这样一套工作机制. ...