1. 题目描述
长度为n的等待队列,tomato处于第m个,有如下四种可能:
(1)激活失败,概率为$p_1$,队列中的顺序不变;
(2)连接失败,概率为$p_2$,队头玩家重新排在队尾;
(3)激活成功,概率为$p_3$,队头出队;
(4)服务器down机,概率为$p_4$,队伍停止。
问当服务器当机时,tomato处在队列前k个人的概率是多少?

2. 基本思路
这显然是个概率DP。dp[i][j]表示队伍中有i个人,tomato处在第j个满足所求的概率。
\begin{align}
    j=1,        (1-p_1) \times dp[i][j] &= p_2 \times dp[i][i] + p_4                                \\
    j\in [2,k], (1-p_1) \times dp[i][j] &= p_2 \times dp[i][j-1] + p_3 \times dp[i-1][j-1] + p_4    \\
    j>k,        (1-p_1) \times dp[i][j] &= p_2 \times dp[i][j-1] + p_3 \times dp[i-1][j-1]
\end{align}
显然,对于$\forall i$均存在i个等式,组成方程组。可以通过(1)式代入,解出dp[i][i]。
注意$p_4 \rightarrow 0$时,即不会发生down机的情况。概率为0。

3. 代码

 /* 4089 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const double eps = 1e-;
const int maxn = ;
double dp[maxn][maxn];
double P[maxn];
int n, kth, k;
double p1, p2, p3, p4; void solve() {
if (p4 < eps) {
puts("0.00000");
return ;
} dp[][] = p4 / (-p1-p2);
double p21 = p2 / (-p1);
double p31 = p3 / (-p1);
double p41 = p4 / (-p1);
rep(i, , n+) {
double coef = 0.0, cons = 0.0; rep(j, , i+) {
if (j == ) {
coef = p21;
cons = p41;
} else if (j <= k) {
cons = p41 + p31 * dp[i-][j-] + p21 * cons;
coef = p21 * coef;
} else {
cons = p31 * dp[i-][j-] + p21 * cons;
coef = p21 * coef;
}
} dp[i][i] = cons / (1.0 - coef);
rep(j, , i) {
if (j == ) {
dp[i][j] = p21 * dp[i][i] + p41;
} else if (j <= k) {
dp[i][j] = p21 * dp[i][j-] + p31 * dp[i-][j-] + p41;
} else {
dp[i][j] = p21 * dp[i][j-] + p31 * dp[i-][j-];
}
}
} double ans = dp[n][kth];
printf("%.05lf\n", ans);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (cin >> n >> kth >> k >> p1 >> p2 >> p3 >> p4) {
solve();
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

最新文章

  1. arrayLiist的四种遍历方法
  2. [转]Linux df 命令不更新磁盘数据空间使用情况的解决办法
  3. python学习笔记七 初识socket(进阶篇)
  4. OpenMP对于嵌套循环应该添加多少个parallel for 分类: OpenMP C/C++ Linux 2015-04-27 14:48 53人阅读 评论(0) 收藏
  5. block iOS 块
  6. 如何将Java源代码文件的编码从GBK转为UTF-8?
  7. vps使用(centos)
  8. Button标签自动刷新问题
  9. freemarker之数组
  10. 从零开始学习PYTHON3讲义(十三)记事本的升级版:网络记事本
  11. EasyUI整合篇
  12. linux服务器间文件夹拷贝
  13. doc命令大全(详细版)
  14. Android Spinner 设置setOnItemSelectedListener时,竟会默认触发一次事件!
  15. .net core 问题:413 Request Entity Too Large nginx
  16. 【代码笔记】iOS-Transition动画
  17. block(五)用法
  18. nginx之编译安装
  19. 1025 PAT Ranking (25)(25 point(s))
  20. NGINX 如何防盗链

热门文章

  1. stl::search
  2. 关于socket阻塞与非阻塞情况下的recv、send、read、write返回值(转载)
  3. solaris bind 符号未定义
  4. datepicker 日期连续选择(需要改源码)
  5. github项目filter_firewall说明
  6. Android:启动引导页实现
  7. tomcat源码解读(1)–tomcat热部署实现原理
  8. Yii框架中集成phprpc、hprose
  9. ofbiz进阶之实体引擎配置文件
  10. 【BZOJ 2744 】[HEOI2012]朋友圈