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 ;
}

最新文章

  1. angularjs+微信,解决chooseImage不能预览的问题
  2. Linux系统管理命令之用户管理
  3. 在CentOS上安装ZooKeeper集群
  4. ServletContext中常用方法
  5. (旧)子数涵数&#183;Flash——影片剪辑的事件操作
  6. Java 集合系列 14 hashCode
  7. MSSQLSERVER数据库- 数据类型Timestamp
  8. selenium webdriver python 开始
  9. 用python输出汉字字库
  10. bzoj 3620: 似乎在梦中见过的样子
  11. 【BZOJ2843】极地旅行社(Link-Cut Tree)
  12. 经典Console案例
  13. 自定义switchButton
  14. TCP 总结
  15. Arch Linux 软件包的查询及清理
  16. sed -i命令详解
  17. [POI2011]Śmieci
  18. 初识DOM
  19. [翻译] TCBlobDownload
  20. MySQL练习-主外键多表查询

热门文章

  1. 当view为wrap_conten时获取一个view的具体宽高
  2. Android: 在native中访问assets全解析
  3. 对国内IoT的展望
  4. SQL Server 数据库部分常用语句小结(二)
  5. js动态创建元素之一--document.write
  6. AngularJS学习之旅—AngularJS HTML DOM(十三)
  7. Bootstrap -- 导航栏样式、分页样式、标签样式、徽章样式
  8. (原创)超详细一步一步在eclipse中配置Struts2环境,无基础也能看懂
  9. requests的基本用法
  10. HBase2.0中的Benchmark工具 — PerformanceEvaluation