hdu4089 Activation
来源:互联网 发布:windows 平板 2017 编辑:程序博客网 时间:2024/06/05 01:17
Activation
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 879 Accepted Submission(s): 314
Problem Description
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.
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.
Input
There 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.
Output
A 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.
The answer should be rounded to 5 digits after the decimal point.
Sample Input
2 2 1 0.1 0.2 0.3 0.43 2 1 0.4 0.3 0.2 0.14 2 3 0.16 0.16 0.16 0.52
Sample Output
0.304270.232800.90343
Source
2011 Asia Beijing Regional Contest
这题,状态转移方程好写,化简真心难化,再者,我们要注意,这题有个小陷阱,就是p4无穷小是,直接输出!
我们可以看出,这题和求期望,是差不多的!
我们用dp[i][j],表示有i个人在排队,他排第j个,达到题目要求的情况的概率,那么我们可以得到
j=1 时,dp[i][j]=p1*dp[i][j]+p2*dp[i][i]+p4;
j>=2&&j<=k时,dp[i][j]=p1*dp[i][j]+p2*dp[i][j-1]+p3*dp[i-1][j-1]+p4;
j>k dp[i][j]=p1*dp[i][j]+p2*dp[i][j-1]+p3*dp[i-1][j-1];
化简得到
dp[i][j]=p21*dp[i][i]+p41;
dp[i][j]=p21*dp[i][j-1]+p31*dp[i-1][j-1]+p41;
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);
这样,我们可以看出,dp[i][i],在第一个式子,和最后一个式子都出现了,我们可以用迭代法把变量消去,得到dp[i]i]=sum{ck*p[i-k])/(1-p[i]),其中k>=1&&k<=i;
这样,我们就可以马上,得到最终的结果了!
#include <iostream>#include <stdio.h>#include <string.h>#define eps 1e-5#define MAXN 2050double dp[MAXN][MAXN],p[MAXN],c[MAXN];using namespace std;int main(){ int n,m,k,i,j; double p1,p2,p3,p4,p21,p31,p41,temp; while(scanf("%d%d%d%lf%lf%lf%lf",&n,&m,&k,&p1,&p2,&p3,&p4)!=EOF) { if(p4<eps) { printf("0.00000\n"); continue; } p21=p2/(1.0-p1),p31=p3/(1.0-p1),p41=p4/(1.0-p1); p[0]=1.0; for(i=1;i<=n;i++) p[i]=p[i-1]*p21; dp[1][1]=p41/(1.0-p21);c[1]=p41; for(i=2;i<=n;i++) { for(j=2;j<=k;j++) c[j]=p31*dp[i-1][j-1]+p41; for(j=k+1;j<=i;j++) c[j]=p31*dp[i-1][j-1]; for(temp=0.0,j=1;j<=i;j++) temp+=c[j]*p[i-j]; dp[i][i]=temp/(1.0-p[i]); dp[i][1]=p21*dp[i][i]+c[1]; for(j=2;j<i;j++) dp[i][j]=dp[i][j-1]*p21+c[j]; } printf("%.5f\n",dp[n][m]); } return 0;}
- hdu4089 Activation
- HDU4089 Activation
- hdu4089 Activation
- hdu4089 Activation
- hdu4089 Activation (概率dp)
- HDU4089-Activation(概率DP)
- HDU4089 Activation 概率DP
- 【HDU4089】Activation-概率DP好题
- hdu4089 Activation 概率dp 2011北京区域赛
- hdu4089(概率DP)
- hdu4089(公式推导)概率dp
- HDU4089概率dp解题报告
- activation.jar
- activation.exe
- Activation Function
- Activation Function
- Activation HDU
- JBOSS:javax/activation/DataHandler
- Content-Disposition的使用和注意事项
- 我开发的插件目录
- Ironpython 安装numpy包
- tornado target server 配置
- 排序算法--shell排序
- hdu4089 Activation
- 数据结构与程序设计 编程原则
- Java设计模式-代理模式
- linux 内存分配机制 (转)
- 编程规则
- 黑马程序员 交通灯管理系统的分析与理解
- (WEB开发者)J2EE中你必须了解的13种技术规范
- 边双联通及其缩点
- 黑马程序员 银行业务调度系统的分析与理解