HDU 4089 활성화 확률 DP
Activation
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2382 Accepted Submission(s): 832
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
Source
2011 Asia Beijing Regional Contest
구현 코드 는 다음 과 같 습 니 다:
/*
HDU 4098
: n 。Tomato m 。
。 :
1、 , ( p1)
2、 , , ( p2)
3、 , ( p3)
4、 , , 。
Tomato <=k
:
DP;
dp[i][j] i ,Tomato j , (j<=i)
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;
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]=p*dp[i][i]+p41;
2<=j<=k: dp[i][j]=p*dp[i][j-1]+p31*dp[i-1][j-1]+p41;
k<j<=i: 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][1~i] i
j==1: dp[i][1]=p*dp[i][i]+c[1];
2<=j<=k:dp[i][j]=p*dp[i][j-1]+c[j];
k<j=i: dp[i][j]=p*dp[i][j]+c[j];
c[j] 。 dp[i] 。
dp[i][i]. dp[i] 。
。 p4<eps , , 0
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define eps 1e-10
#define N (1<<7)+5
#define zero(a) (fabs(a)<eps)
using namespace std;
double p1,p2,p3,p4,p21,p31,p41;
double dp[2005][2005],c[2005];
int n,m,k;
int main()
{
while(scanf("%d%d%d%lf%lf%lf%lf",&n,&m,&k,&p1,&p2,&p3,&p4)!=EOF)
{
if(zero(p4)) {puts("0.00000");continue;}
p21=p2/(1-p1);
p31=p3/(1-p1);
p41=p4/(1-p1);
dp[1][1]=p4/(1-p1-p2);
for(int i=2;i<=n;i++)
{
for(int j=2;j<=(i<k?i:k);j++)
c[j]=dp[i-1][j-1]*p31+p41;
for(int j=k+1;j<=i;j++)
c[j]=dp[i-1][j-1]*p31;
double p=1,tmp=0;
for(int j=i;j>1;j--)
{
tmp+=p*c[j];
p*=p21;
}
dp[i][i]=(tmp+p*p41)/(1-p*p21);
dp[i][1]=p21*dp[i][i]+p41;
for(int j=2;j<i;j++)
dp[i][j]=p21*dp[i][j-1]+c[j];
}
printf("%.5f
",dp[n][m]);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.