HDU 4089Activation 概率dp好题
来源:互联网 发布:js中生成随机整数 编辑:程序博客网 时间:2024/06/04 18:32
Description
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
Output
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
题意如下
有1到n个玩家在服务器队列中等待进入游戏
每次服务器会有以下的4种情况
i) 服务器故障导致什么都没发生
ii) 当前玩家被转移到队列最后面
iii) 成功登陆游戏
iiii) 服务器奔溃 所有人还在队列里
对应的概率 为 p1、p2、p3,p4
问当服务器奔溃时候在玩家A前面的人不超过k-1个人的概率
·规定 dp【i,j】 表示服务器奔溃时候队列有i个人 A现在在j位置
那么当j==1时候
可以知道其中一种情况是 dp【i,j】=dp【i,j】*p1+dp【i,i】*p2+p4;
j<k的时候 dp【i,j】=dp【i,j】*p1+dp【i,j】*p2+dp【i-1,j-1】*p3+p4;
j>=k的时候 dp【i,j】=dp【i,j】*p1+dp【i,j】*p2+dp【i-1,j-1】*p3;
因为p1的情况会出现无限循环
然后 根据 级数可以把这种情况转化为1/(1-p1)
所以我们令 p21=p2/(1-p1),p31=p3/(1-p1),p41=p4/(1-p1);
所以状态转移方程可以转化成
j==1 dp【i,j】=dp【i,i】*p21+p41;
j<k的时候dp【i,j】=dp【i,j】*p21+dp【i-1,j-1】*p31+p41;
j>=k的时候 dp【i,j】=dp【i,j】*p21+dp【i-1,j-1】*p31;
可以循环i=1->n 递推求解dp[i].在求解dp[i]的时候dp[i-1]就相当于常数了。
在求解dp【i,1~i】时等到下列i个方程
j==1: dp【i,1】=dp【i,i】*p21+c【1】;
j<=k: dp【i,j】 =dp【i,j-1】*p21+c【j】;
k<j=i: dp【i,j】 =dp【i,j】+c【j】;
其中c[j]都是常数了。上述方程可以解出dp[i]了。
首先是迭代得到 dp[i][i].然后再代入就可以得到所有的dp[i]了。
貌似后台改数据了 需要用滚动数组来优化空间
ACcode:
#include<stdio.h>#define maxn 2020#define eps 1e-5double c[maxn];double pp[maxn];double dp[2][maxn];int main(){ int n,m,k; double p1,p2,p3,p4; while(~scanf("%d%d%d%lf%lf%lf%lf",&n,&m,&k,&p1,&p2,&p3,&p4)){ if(p4<eps){puts("0.00000");continue;} double p21=p2/(1-p1),p31=p3/(1-p1),p41=p4/(1-p1); pp[0]=1.0; for(int i=1;i<=n;i++) pp[i]=p21*pp[i-1]; dp[1][1]=p41/(1-p21); 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]; double tmp=c[1]*pp[i-1]; for(int j=2;j<=k;j++)tmp+=c[j]*pp[i-j]; for(int j=k+1;j<=i;j++)tmp+=c[j]*pp[i-j]; dp[i&1][i]=tmp/(1-pp[i]); dp[i&1][1]=p21*dp[i&1][i]+c[1]; for(int j=2;j<i;j++)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 4089Activation 概率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
- HDU 4089 Activation【概率DP】
- HDU-4089 Activation(概率DP)
- Hdu 4089 Activation 概率DP
- HDU 4089 Activation(概率DP好题)——2011 Asia Beijing Regional Contest
- Redis和Memcache的区别
- caffe学习笔记2:Fine-tuning一个类别识别的预处理的网
- kmp算法的原理
- 用Java代码打印菱形
- JVM内核—JVM内存模型
- HDU 4089Activation 概率dp好题
- 共同学习Java源代码--数据结构--AbstractList抽象类(四)
- Kruskal算法
- ZOJ 3869:Ace of Aces【水】
- 使用Visual Studio开发C程序
- 轮播图-鼠标滑入图片,停止轮播,鼠标划出后,启动轮播
- linux 下部署项目可能遇到的问题
- 第十周第十一周项目1阅读程序(2)
- 结构体字节对齐