http://acm.hdu.edu.cn/showproblem.php?pid=4089

Activation

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1500    Accepted Submission(s):
570

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.
 
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.
 
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
学习:当前面的未知数,而后面也有未知数,看是否有常数项,最后列出一元一次方程。
题意:
有n人都是仙剑5的fans,现在要在官网上激活游戏,n个人排成一个队列(其中主角Tomato最初排名为m),
对于队列中的第一个人,在激活的时候有以下五种情况:
    1.激活失败:留在队列中继续等待下一次激活(概率p1)
    2.失去连接:激活失败,并且出队列然后排到队列的尾部(概率p2)
    3.激活成功:出队列(概率p3)
    4.服务器瘫:服务器停止服务了,所有人都无法激活了(概率p4)
求服务器瘫痪并且此时Tomato的排名<=k的概率。
题解:
是一个概率题,分析一下题意后发现和“dp求期望”的题目有点像,因为其中都有一种死循环的可能,
该题中,如果总是发生p1概率的情况那就是死循环了。然后想到一个二维dp:
dp[i][j]表示队列中有i个人,Tomato排在第j个,能发生所求事件的概率。
显然,dp[n][m]即为所求。
j == 1 : dp[i][1] = p1*dp[i][1] + p2*dp[i][i]   + p4;
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];
化简:
j == 1 : dp[i][1] = p*dp[i][i]   + p41;
2<=j<=k: dp[i][j] = p*dp[i][j-1] + p31*dp[i-1][j-1] + p41;
j > k  : dp[i][j] = p*dp[i][j-1] + p31*dp[i-1][j-1];
其中:
p   = p2 / (1 - p1);
p31 = p3 / (1 - p1);
p41 = p4 / (1 - p1);
现在可以循环 i = 1 -> n 递推求解dp[i],所以在求dp[i]时,dp[i-1]就相当于常数了,
设dp[i][j]的常数项为c[j]:
j == 1 : dp[i][1] = p*dp[i][i]   + c[1];
2<=j<=k: dp[i][j] = p*dp[i][j-1] + c[j];
j > k  : dp[i][j] = p*dp[i][j-1] + c[j];
在求dp[i]时,就相当于求“i元1次方程组”:
dp[i][1] = p*dp[i][i] + c[1];
dp[i][2] = p*dp[i][1] + c[2];
dp[i][3] = p*dp[i][2] + c[3];
...

dp[i][i] = p*dp[i][i-1] + c[i];

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const double eps=1e-;
double dp[][];
double pp[],c[];
int main()
{
int n,m,k,i,j;
double p1,p2,p3,p4;
while(~scanf("%d%d%d",&n,&m,&k))
{
memset(dp,,sizeof(dp));
scanf("%lf%lf%lf%lf",&p1,&p2,&p3,&p4);
if(p4<eps)
{
printf("0.00000\n");
continue;
}
dp[][]=p4/(-(p1+p2));
double p=p2/(-p1);
double p31=p3/(-p1);
double p41=p4/(-p1);
c[]=p41;
pp[]=;
for(i=;i<=n;i++)
pp[i]=p*pp[i-];
for(i=;i<=n;i++)
{
for(j=;j<=k&&j<=i;j++)
c[j]=p31*dp[i-][j-]+p41;
for(j=k+;j<=n&&j<=i;j++)
c[j]=p31*dp[i-][j-];
double temp=c[]*pp[i-];
for(j=;j<=n;j++)
temp+=c[j]*pp[i-j];
dp[i][i]=temp/(-pp[i]);
dp[i][]=p*dp[i][i]+c[];
for(j=;j<i;j++)
dp[i][j]=p*dp[i][j-]+c[j];
}
printf("%.5lf\n",dp[n][m]);
}
return ;
}

HDU-4089 Activation的更多相关文章

  1. HDU 4089 Activation 概率DP 难度:3

    http://acm.hdu.edu.cn/showproblem.php?pid=4089 这道题中一共有两个循环: 1.事件1 如果一直落在Activation failed事件上,那么就会重新继 ...

  2. HDU 4089 Activation:概率dp + 迭代【手动消元】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4089 题意: 有n个人在排队激活游戏,Tomato排在第m个. 每次队列中的第一个人去激活游戏,有可能 ...

  3. HDU 4089 Activation(概率DP)(转)

    11年北京现场赛的题目.概率DP. 公式化简起来比较困难....而且就算结果做出来了,没有考虑特殊情况照样会WA到死的.... 去参加区域赛一定要考虑到各种情况.   像概率dp,公式推出来就很容易写 ...

  4. [HDU 4089]Activation[概率DP]

    题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...

  5. 【HDU】4089 Activation

    http://acm.hdu.edu.cn/showproblem.php?pid=4089 题意: 有n个人排队等着在官网上激活游戏.主角排在第m个. 对于队列中的第一个人.有以下情况:1.激活失败 ...

  6. Activation HDU - 4089(概率dp)

    After 4 years' waiting, the game "Chinese Paladin 5" finally comes out. Tomato is a crazy ...

  7. HDU 4089 && UVa 1498 Activation 带环的概率DP

    要在HDU上交的话,要用滚动数组优化一下空间. 这道题想了很久,也算是想明白了,就好好写一下吧. P1:激活游戏失败,再次尝试. P2:连接失服务器败,从队首排到队尾. P3:激活游戏成功,队首的人出 ...

  8. Activation(hdu 4089)

    题目:仙5的激活序列.有以下4种情况: 1.注册失败,但是不影响队列顺序 ,概率为p1 2.连接失败,队首的人排到队尾,概率为p2 3.注册成功,队首离开队列,概率为p3 4.服务器崩溃,激活停止,概 ...

  9. Activation HDU - 4089 (概率DP)

    kuangbin的博客 强 #include <bits/stdc++.h> using namespace std; const int MAXN = 2005; const doubl ...

  10. 【HDOJ】4089 Activation

    1. 题目描述长度为n的等待队列,tomato处于第m个,有如下四种可能:(1)激活失败,概率为$p_1$,队列中的顺序不变:(2)连接失败,概率为$p_2$,队头玩家重新排在队尾:(3)激活成功,概 ...

随机推荐

  1. U3D 摄像机镜头控制

    如果要实现,摄像机跟随着主角运动,还有运用滚轮实现镜头的方法和缩小的实现原理 方法1:把主摄像机放到主角的下面,作为一个子对象,调整好摄像机的视角,此时就会跟随了. 方法2:用代码让摄像机的相关的po ...

  2. [Jquery] jQuery.cookie帮助类 (转载)

    /** * Cookie plugin * * Copyright (c) [url=http://sufei.cnblogs.com/]http://sufei.cnblogs.com[/url] ...

  3. GCDTimer

    #import <Foundation/Foundation.h> @interface JKTimerManager : NSObject + (instancetype)sharedT ...

  4. winfrom面向对象1

    1:面向对象的技术概论 要学习好面向对象,我们应该从三个问题入手: 1.什么是面向对象? 2.为什么要面向对象? 3.该怎么面向对象? 对象的定义是人们要进行研究的任何事物,从最简单的整数到复杂的飞机 ...

  5. DOM&SAX解析XML

    在上一篇随笔中分析了xml以及它的两种验证方式.我们有了xml,但是里面的内容要怎么才能得到呢?如果得不到的话,那么还是没用的,解析xml的方式主要有DOM跟SAX,其中DOM是W3C官方的解析方式, ...

  6. angularjs应用骨架(2)

    时隔一个星期,接着上一篇的angularjs应用骨架继续聊聊angularjs其他的其他的内容. 区分UI和控制器的职责 在应用控制器中有三种职责: 1.为应用中模型设置初始状态 2.通过$scope ...

  7. [学习笔记]设计模式之Command

    为方便读者,本文已添加至索引: 设计模式 学习笔记索引 写在前面 在上篇Chain of Responsibility(职责链)模式笔记中,我们学习了一种行为型设计模式.今天,我们继续这一主题,来学习 ...

  8. 『重构--改善既有代码的设计』读书笔记----Change Reference to Value

    如果你有一个引用对象,很小且不可改变,而且不易管理,你就需要考虑将他改为一个值对象.在Change Value to Reference我们说过,要在引用对象和值对象之间做选择,有时候并不容易,有了重 ...

  9. eclipse下使用Genymotion调试Android程序出现的问题

    一. The connection to adb is down, and a severe error has occured. You must restart adb and Eclipse. ...

  10. oracle删除用户所有表

    在删除数据表的时候往往遇到外键约束无法删除的情况,我们可以通过以下几步将数据库表删除,建议在删除库之前先对数据库进行备份,养成良好习惯. 1.删除外键 --查询用户所有表的外键,owner条件为use ...