HDU-4089 Activation(概率DP)
来源:互联网 发布:万网域名如何解析 编辑:程序博客网 时间:2024/05/17 03:26
Activation
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.
The answer should be rounded to 5 digits after the decimal point.
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
0.304270.232800.90343
题目大意:Tomato正在一个有n人的队列中的第m号位置,每次队首的人会遇到四种情况:
①激活失败,概率为p1,然后继续在队首激活;
②连接失败,概率为p2,然后排在队尾等在激活;
③激活成功,概率为p3,然后离开队伍;
④服务器瘫痪,概率为p4,所有队伍中的人都无法进行激活。
求Tomato在服务器瘫痪时,前面排队的人数少于k-1时的概率?
设dp[i][j]表示有i人队,排在第j号位置时,达到目标状态的概率,初始:dp[1][1]=p4/(1-p1-p2),则dp[n][m]即为答案
则状态转移方程为:
①j==1:dp[i][1]=p1*dp[i][1]+p2*dp[i][i]+p4;
②1<j<=k:dp[i][j]=p1*dp[i][j]+p2*dp[i][j-1]+p3*dp[i-1][j-1]+p4;
③k<j<=i:dp[i][j]=p1*dp[i][j]+p2*dp[i][j-1]+p3*dp[i-1][j-1];
①j==1:dp[i][1]=(p2*dp[i][i]+p4)/(1-p1);
②1<j<=k:dp[i][j]=(p2*dp[i][j-1]+p3*dp[i-1][j-1]+p4)/(1-p1);
③k<j<=i:dp[i][j]=(p2*dp[i][j-1]+p3*dp[i-1][j-1])/(1-p1);
①j==1:dp[i][1]=p21*dp[i][i]+c[1];
②1<j<=k:dp[i][j]=p21*dp[i][j-1]+c[j];
③k<j<=i:dp[i][j]=p21*dp[i][j-1]+c[j];
每一项都带入后得:dp[i][i]=dp[i][i]*(p21^i)+c[1]*(p21^(i-1))+c[2]*(p21^(i-2))+…+c[j]*(p21^(i-j))+…+c[i];
然后可以求得:dp[i][i],dp[i][1],再带入递推求解即可#include <cstdio>using namespace std;const int MAXN=2005;int n,m,k;double p1,p2,p3,p4,p21,p31,p41,tmp;double dp[2][MAXN];//dp[i][j]表示有i人队,排在第j号位置时,达到目标状态的概率double c[MAXN],p[MAXN];//p[i]表示p21^iint main() { while(7==scanf("%d%d%d%lf%lf%lf%lf",&n,&m,&k,&p1,&p2,&p3,&p4)) { if(-0.000001<p4&&p4<0.000001) {//如果瘫痪的概率为0,则无法达到目标状态 printf("0.00000\n"); continue; } p21=p2/(1-p1); p31=p3/(1-p1); p41=p4/(1-p1); p[0]=1; for(int i=1;i<=n;++i) { p[i]=p21*p[i-1]; } dp[1][1]=p4/(1-p1-p2); c[1]=p41; for(int i=2;i<=n;++i) { for(int j=2;j<=k;++j) { c[j]=p31*dp[(i-1)&1][j-1]+p41; } for(int j=k+1;j<=i;++j) { c[j]=p31*dp[(i-1)&1][j-1]; } tmp=0; for(int j=1;j<=i;++j) { tmp+=p[i-j]*c[j]; } dp[i&1][i]=tmp/(1-p[i]); dp[i&1][1]=p21*dp[i&1][i]+c[1]; for(int j=2;j<i;++j) {//递推算出dp[i][2~(i-1)] dp[i&1][j]=p21*dp[i&1][j-1]+c[j]; } } printf("%.5lf\n",dp[n&1][m]); } return 0;}
- hdu 4089 Activation(概率dp)
- hdu 4089 Activation(概率dp)
- Hdu 4089 Activation(概率DP)
- HDU 4089 Activation (概率DP )
- hdu 4089 Activation(概率dp)
- HDU-4089 Activation(概率DP)
- HDU 4089 Activation(概率dp)
- HDU 4089 Activation(概率DP)
- hdu 4089 Activation 概率DP
- 概率dp-hdu-4089-Activation
- [HDU 4089]Activation[概率DP]
- 概率dp HDU 4089 Activation
- hdu-4089-Activation-概率dp
- 【HDU】 4089 Activation 概率DP
- hdu 4089 Activation 概率dp
- 概率DP hdu 4089 Activation
- HDU 4089 Activation(概率DP)
- HDU 4089 Activation 概率dp
- NYOJ 710 外星人的供给站
- 剑指offer矩形覆盖问题
- Android Volley 之自定义Request
- [转载] 玩转CPU Topology(NUMA、SMP、Socket、physical Processor、Core、Logical Processor、Cache)
- 聚铭网络科技-信息安全专家
- HDU-4089 Activation(概率DP)
- AWS EMR上搭建HBase环境
- css记录
- greenplum之gpload常见问题集
- 收集全库统计信息的解释
- 指针变量的使用
- 打印spi GUID
- Android JNI 接口总结
- 从源码的角度带你分析Glide整体加载流程以及设计模式