您的位置:首页 > 其它

HDU 3076 ssworld VS DDD 【概率dp】

2017-07-01 16:12 246 查看


ssworld VS DDD

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2646    Accepted Submission(s): 530


Problem Description

One day, sssworld and DDD play games together, but there are some special rules in this games.

They both have their own HP. Each round they dice respectively and get the points P1 and P2 (1 <= P1, P2 <= 6). Small number who, whose HP to reduce 1, the same points will remain unchanged. If one of them becomes 0 HP, he loses. 

As a result of technical differences between the two, each person has different probability of throwing 1, 2, 3, 4, 5, 6. So we couldn’t predict who the final winner. 

 

Input

There are multiple test cases.

For each case, the first line are two integer HP1, HP2 (1 <= HP1, HP2 <= 2000), said the first player sssworld’s HP and the second player DDD’s HP. 

The next two lines each have six floating-point numbers per line. The jth number on the ith line means the the probability of the ith player gets point j. The input data ensures that the game always has an end. 

 

Output

One float with six digits after point, indicate the probability sssworld won the game.

 

Sample Input

5 5
1.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 1.000
5 5
0.000 0.000 0.000 0.000 0.000 1.000
1.000 0.000 0.000 0.000 0.000 0.000

 

Sample Output

0.000000
1.000000

 

Source

2009 Multi-University Training Contest 17 - Host
by NUDT

 

Recommend

lcy

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
const int M=1e3+10;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int i,j,k,n,m;
double a[M],b[M];
double ans;
double aw,bw;
double dp[2001][2001];

int main()
{
while(~scanf("%d%d",&n,&m)){
for(int i=1;i<=6;i++)scanf("%lf",&a[i]);
for(int i=1;i<=6;i++)scanf("%lf",&b[i]);
aw=bw=0;
for(int i=2;i<=6;i++)
for(int j=1;j<i;j++){
aw+=a[i]*b[j];
bw+=b[i]*a[j];
}
double p1=aw;
double p2=bw;
double p=1-p1-p2;
if(p==1){
printf("0.000000\n");
continue;
}
else {
aw=p1/(1-p);
bw=p2/(1-p);
}
dp[0][0]=1;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
if(i==0&&j==0)continue;
dp[i][j]=0;
if(i>0)dp[i][j]+=dp[i-1][j]*aw;
if(j>0)dp[i][j]+=dp[i][j-1]*bw;

}
ans=0;
for(int i=0;i<m;i++)
ans+=dp[n-1][i]*aw;
if(ans>1)ans=1;
printf("%.6lf\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: